Ubuntu18.04 安装npm

本文介绍了在Ubuntu 18.04系统中安装npm时遇到的依赖问题,包括如何解决node-gyp未安装导致的错误,并详细讲述了安装Node.js的不同步骤,以及查看版本的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值