Ubuntu 14.04自帶的node是0.10.x的,想安裝4.x的版本,網(wǎng)上查了一下,有的說編譯源代碼什么的,太麻煩。既然有編譯好的版本,完全沒必要自己編譯??!這里就有各個(gè)發(fā)布版及其安裝辦法,照著方法安裝一下就好了。
wget -qO- https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
npm -v
但是現(xiàn)實(shí)情況中并不是這么順利的,中途還會(huì)出現(xiàn)各種問題。。。以下記錄幾個(gè)遇到的問題。
apt-get update 時(shí)簽名無法驗(yàn)證的問題
錯(cuò)誤信息:
“the following signatures couldn’t be verified because the public key is not available”
解決方法看這里。
apt-get update 時(shí)404的問題
錯(cuò)誤信息:
Err http://security.ubuntu.com raring-security/main amd64 Packages 404 Not Found [IP: 91.189.91.15 80]
有的地方說,要把/etc/apt/sources.list這個(gè)文件中的archive.ubuntu.com 和security.ubuntu.com這兩個(gè)網(wǎng)址換成old-releases.ubuntu.com。但是我換了之后,發(fā)現(xiàn)連IP地址都找不到了。不太清楚是什么原因。
還會(huì)跑出來“Hash sum mismatch”這個(gè)錯(cuò)誤。這個(gè)方法也試了,不過沒有什么作用:
sudo rm /var/lib/apt/lists/* -vf
sudo apt-get update
沒有什么好辦法,直接換國(guó)內(nèi)的源算了,比如阿里云的源。
Ubuntu 14.04 更換阿里云的源
修改apt源文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #備份
sudo vim /etc/apt/sources.list #修改,然后把下面的阿里云源地址粘貼進(jìn)去
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