Ubuntu 14.04自带的node是0.10.x的,想安装4.x的版本,网上查了一下,有的说编译源代码什么的,太麻烦。既然有编译好的版本,完全没必要自己编译啊!这里就有各个发布版及其安装办法,照着方法安装一下就好了。
wget -qO- https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm -v
但是现实情况中并不是这么顺利的,中途还会出现各种问题。。。以下记录几个遇到的问题。
apt-get update 时签名无法验证的问题
错误信息:
“the following signatures couldn’t be verified because the public key is not available”
解决方法看这里。
apt-get update 时404的问题
错误信息:
Err http://security.ubuntu.com raring-security/main amd64 Packages 404 Not Found [IP: 91.189.91.15 80]
有的地方说,要把/etc/apt/sources.list这个文件中的archive.ubuntu.com 和security.ubuntu.com这两个网址换成old-releases.ubuntu.com。但是我换了之后,发现连IP地址都找不到了。不太清楚是什么原因。
还会跑出来“Hash sum mismatch”这个错误。这个方法也试了,不过没有什么作用:
sudo rm /var/lib/apt/lists/* -vf
sudo apt-get update
没有什么好办法,直接换国内的源算了,比如阿里云的源。
Ubuntu 14.04 更换阿里云的源
修改apt源文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份
sudo vim /etc/apt/sources.list #修改,然后把下面的阿里云源地址粘贴进去
sudo apt-get update #更新列表
阿里云源地址
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
参考
https://www.yurendu.com/code/16.html
http://askubuntu.com/questions/672994/how-to-install-nodejs-4-using-apt
https://github.com/nodesource/distributions
https://chrisjean.com/fix-apt-get-update-the-following-signatures-couldnt-be-verified-because-the-public-key-is-not-available/
http://askubuntu.com/questions/553765/failed-to-fetch-update-on-ubuntu-14-04-lts-trusty-tahr