Ubuntu18.04 安装npm
1.安装npm
sudo apt-get install npm
安装不了,报错:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
需要加一句
sudo apt-get install nodejs-dev node-gyp libssl1.0-dev
sudo apt-get install npm
2.安装node
运行命令:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
安装node时,一直报错,解决办法
将etc/apt/sources.list.d
文件先全部备份
sudo mv etc/apt/sources.list.d etc/apt/sources.list.d.bak
然后新建etc/apt/sources.list.d
文件夹,里面新建nodesource.list
文件
文件内写入:
deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_14.x bionic main
然后再执行curl
命令
提示安装nodejs,再安装即可
3.安装nodejs
sudo apt-get install -y nodejs
4.查看安装版本
npm -v
node -v
nodejs -v
qiancj@qianchengjun:~$ npm -v
6.14.16
qiancj@qianchengjun:~$ node -v
v14.19.1
qiancj@qianchengjun:~$ nodejs -v
v14.19.1