安装最新版nodejs

更新ubuntu软件源
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

安装nodejs

sudo apt-get install nodejs
sudo apt install nodejs-legacy
sudo apt install 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版本)

sudo n stable
sudo node -v

QA

Q: 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() 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. // A: 修改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

Q: node -v异常

node -v
-bash: /usr/local/bin/node: Permission denied sudo node -v
Segmentation fault (core dumped) // A: 重新安装nodejs
手动移除 /usr/local/lib/node_modules整个目录
手动移除 /usr/local/bin/node
手动移除 /usr/local/bin/n
手动移除 /usr/local/bin/npm

ubuntu软件源

修改/etc/apt/sources.list为以下软件源(改前请备份)
163和里面在部分网络下会一直下载失败,可以改回官方源下载

源列表

http://wiki.ubuntu.org.cn/模板:16.04source

Ubuntu官方
deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse

小礼物走一走,来简书关注我

作者:十戒s
链接:https://www.jianshu.com/p/2b24cd430a7d
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

最新文章

  1. 如何用Dockerfile创建镜像
  2. html画布
  3. CFDebug.template
  4. Java日志——2016.6.3
  5. 转 漫谈linux文件IO
  6. PL/pgSQL学习笔记之十
  7. C#_模拟webAp_POST-GET-PUT-DELETE
  8. C++primer(第五版)读书笔记&习题解答---CHAPTER 3
  9. Surprising Strings(map类)
  10. HDOJ 4937 Lucky Number
  11. nginx+keepalived+tomcat之具体配置档
  12. Struts2 拦截器具体配置过程
  13. 打印杨辉三角 --JS
  14. spring mvc底层(DispacherServlet)的简单实现
  15. CentOS使用systemctl daemon-reload报错Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)解决办法
  16. VirtualBox fedora29 安装
  17. angular.copy(source, destination)
  18. Java 从服务器下载文件到本地(页面、后台、配置都有)
  19. MySQL:基础知识
  20. navigator 判断移动端是Android还是iOS

热门文章

  1. linux 几个逼格高实用的命令
  2. 三:JMS消息服务规范
  3. javascript 中的深复制 和 其实现方法
  4. Binary Tree Inorder Traversal-非递归实现中序遍历二叉树
  5. DefaultTableCellRenderer 自定义
  6. Java虚拟机学习 - 体系结构 内存模型(转载)
  7. [bzoj2440]完全平方数(二分+mobius反演)
  8. how to run faster
  9. 删除win7快捷方式小箭头
  10. 1.4 DVWA亲测文件上传漏洞