安裝 debian && ubuntu
安裝過程就不必過多贅述了,網(wǎng)上相關(guān)教程已經(jīng)汗牛充棟了逛绵。
不過要注意的是嫉入,linux 子系統(tǒng)對(duì)于 win10 的版本有限制瞎嬉,一般來說,升級(jí)到最新版本是醉吼的救巷。
更換阿里源
1. 查看系統(tǒng)發(fā)行版本
debian
debian@root-pc:zx$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 9.7 (stretch)
Release: 9.7
Codename: stretch
ubuntu
ubuntu@root-pc:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
2. 備份默認(rèn)的源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
3. 找到對(duì)應(yīng)的源替換進(jìn)去(這里以阿里巴巴鏡像源為例)
首先打開頁面 https://opsx.alibaba.com/mirror

找到對(duì)應(yīng)的發(fā)行版系統(tǒng),點(diǎn)擊操作一列的幫助,會(huì)彈出一個(gè)面板(這里以 ubuntu 為例):

可以找到跟我用的發(fā)行版本一致源配置挽懦,將我圈出來的這段配置復(fù)制出來,這里即:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
注意木人,如果你不是用的 ubuntu 18.04(bionic) 發(fā)行版信柿,請(qǐng)不要偷懶直接復(fù)制我上面粘貼的示例配置,請(qǐng)自行打開網(wǎng)頁找到對(duì)應(yīng)版本的配置醒第。
然后要做的就是將上面一段配置渔嚷,替換到我們的 /etc/apt/sources.list
文件中即可 。
至于怎么復(fù)制進(jìn)去稠曼,我這里還是簡(jiǎn)單的說明一下吧形病。
# 1. 用 vim 編輯對(duì)應(yīng)的文件
sudo vim /etc/apt/sources.list
# 2. 執(zhí)行 dG 命令,清空文件
dG
# 3. 黏貼霞幅,這一步視你用的工具不同漠吻,而有差別,比如我是直接用 windows 的 commander蝗岖,所以直接右鍵就黏貼進(jìn)去了
# 4. 保存退出
wq
4. 更新軟件源列表
sudo apt-get update
安裝最新版 nodejs
如果你不是 nodejs 或者前端開發(fā)者侥猩,那么接下來的內(nèi)容你也不用看了。
1. 安裝 nodejs
如果你是的話抵赢,一般情況下欺劳,還是用最新穩(wěn)定版本的 nodejs 比較好些,那么肯定需要裝上最新版本的 nodejs铅鲤,但是如果直接 sudo apt install nodejs
往往安裝的是比較老舊的 nodejs划提,因此可以通過 github 上的一個(gè)項(xiàng)目,來安裝最新版本的 nodejs邢享。
首先進(jìn)入 github 倉庫: https://github.com/nodesource/distributions

下拉鹏往,找到對(duì)應(yīng)的安裝命令:

比如,現(xiàn)在我以 ubuntu 為例骇塘,我想安裝 v12.x 的 nodejs伊履,那么直接在 bash 執(zhí)行以下指令即可
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
2. 清理緩存模塊
sudo npm cache clean -f
3. 用 n 模塊維護(hù) nodejs 版本
這個(gè) n 模塊韩容,是前端界大名鼎鼎的 tj 大神 開發(fā)的方便管理 nodeje 版本的 npm 包,可以說唐瀑,在 Linux 下體驗(yàn)真是賊爽的群凶。
有人說,如果我用 Windows 呢哄辣?也可以裝這個(gè) n 模塊嗎请梢?據(jù)我所知,貌似是不能的力穗,但是 Windows 版本的 nodejs 官網(wǎng)提供了安裝版本和免安裝版本毅弧,根本不需要過來湊這個(gè)熱鬧啊。
sudo npm install -g n
# 安裝最近的一個(gè)穩(wěn)定版
sudo n stable
當(dāng)然這個(gè)模塊当窗,還有很多命令够坐,感興趣的同學(xué)可以研究下文檔。
后記
這里還是說個(gè)題外話吧崖面,上面這個(gè)安裝方法并不是唯一的咆霜。
但是相對(duì)而言,是比較方便的一個(gè)方式嘶朱,便于后續(xù)的切換nodejs 版本蛾坯。
至少是不需要自己去 nodejs 官網(wǎng)下載二進(jìn)制包,解壓后創(chuàng)建鏈接疏遏,設(shè)置環(huán)境變量啥的脉课,更不需要自己下源碼下來編譯安裝。
當(dāng)然财异,對(duì)于大神而言倘零,我還是推薦自己編譯安裝的,畢竟這樣用起來比較放心戳寸。
但是呈驶,我想,我寫的這篇拙文疫鹊,也很難有機(jī)會(huì)被大神看到吧袖瞻。