Ubuntu16.04安装最新版nodejs

更新ubuntu软件源

# Ubuntu 16.04 TLS,执行以下命令:
sudo apt-get update
sudo apt-get install -y python-software-properties software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update


# Ubuntu 18.04 TLS,执行以下命令:
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update

查看ubuntu版本:lsb_release -a
在这里插入图片描述

完整卸载掉node和npm

#apt-get 卸载
sudo apt-get remove --purge npm
sudo apt-get remove --purge nodejs
sudo apt-get remove --purge nodejs-legacy
sudo apt-get autoremove
​
#手动删除 npm 相关目录
rm -r /usr/local/bin/npm
rm -r /usr/local/lib/node-moudels
find / -name npm
rm -r /tmp/npm* 

安装nodejs

# Ubuntu 16.04 TLS,执行以下命令:
sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install npm


# Ubuntu 18.04 TLS,执行以下命令:
sudo apt-get install nodejs
sudo apt install libssl1.0-dev nodejs-dev node-gyp npm

更新npm的包镜像源,方便快速下载

sudo npm config set registry https://registry.npm.taobao.org
sudo npm config list

全局安装n管理器(用于管理nodejs版本)

sudo npm install n -g

安装最新的nodejs(stable版本)

# 安装最新的nodejs(stable版本)
sudo n stable

# 安装指定版本的nodejs(5.1.0)
sudo n 5.1.0

验证安装

sudo node -v
sudo npm -v

安装完最好重启一下:sudo reboot或者重启shell

Q & A

1. apt-get update找不到文件

// error code
W: The repository 'http://ppa.launchpad.net/chris-lea/node.js/ubuntu xenial Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch http://ppa.launchpad.net/chris-lea/node.js/ubuntu/dists/xenial/main/binary-amd64/Packages  404  Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.

修改node相关文件:/etc/apt/sources.list.d/chris-lea-ubuntu-node_js-xenial.list
deb http://ppa.launchpad.net/chris-lea/node.js/ubuntu trusty main
deb-src http://ppa.launchpad.net/chris-lea/node.js/ubuntu trusty main

2. SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

在这里插入图片描述
网上查找资料是因为版本过低,升级node和npm(暂未核对!)

来源: https://www.cnblogs.com/schips/p/12402412.html

3. curl: (56) GnuTLS recv error (-54): Error in the pull function.
原因:由于git默认缓存大小不足导致的。
解决:git config --global http.postBuffer 20000000

这里其实重点是下面的原因,这里陪陪增大了git需要的内存空间,会导致git clone或者git pull等命令因内存不足报错。

  1. cp: cannot stat ‘/usr/local/n/versions/node/12.18.3/lib’: No such file or directory
    原因:未知
    解决:
    cd /usr/local/n/
    rm -rf versions
    
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值