中山做網(wǎng)站建設(shè)聯(lián)系電話中國公關(guān)公司前十名
Linux環(huán)境下安裝Nodejs
下載地址:https://nodejs.org/zh-cn/download/package-manager
一、使用壓縮包自定義安裝
上述鏈接下載好對應(yīng)版本的軟件包后,我存放到 /evn/nodejs 目錄下(根據(jù)自己實際情況設(shè)置)
- 設(shè)置軟鏈接
sudo ln -s /evn/nodejs/node-v16.18.0-linux-x64/bin/npm /usr/local/bin/
sudo ln -s /evn/nodejs/node-v16.18.0-linux-x64/bin/node /usr/local/bin/
- 設(shè)置鏡像源地址
npm config set registry https://registry.npmmirror.com/
- 查看地址是否設(shè)置成功
npm config get registry
- 安裝cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com/
- 設(shè)置軟連接
sudo ln -s /evn/nodejs/node-v16.18.0-linux-x64/bin/cnpm /usr/local/bin/
二、使用nvm命令安裝
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash# download and install Node.js (you may need to restart the terminal)
nvm install 20# verifies the right Node.js version is in the environment
node -v # should print `v20.15.1`# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
相關(guān)命令
- nvm list #查看已經(jīng)安裝的版本
- nvm list installed #查看已經(jīng)安裝的版本
- nvm list available #查看網(wǎng)絡(luò)可以安裝的版本
- nvm version #查看當(dāng)前的版本
- nvm install #安裝最新版本
- nvm nvm use #切換使用指定的版本
- node nvm ls# 列出所有版本 nvm current顯示當(dāng)前版本
- nvm alias #給不同的版本號添加別名
- nvm unalias #刪除已定義的別名
- nvm reinstall-packages 在#當(dāng)前版本node環(huán)境下,重新全局安裝指定版本號的npm包
- nvm on #打開nodejs控制
- nvm off #關(guān)閉nodejs控制
- nvm proxy #查看設(shè)置與代理
- nvm node_mirror [url] #設(shè)置或者查看setting.txt中的node_mirror,如果不設(shè)置的默認是 Index of /dist/
- nvm npm_mirror [url] #設(shè)置或者查看setting.txt中的 npm_mirror,如果不設(shè)置的話默認的是: https://github.com/npm/npm/archive/
- nvm uninstall #卸載制定的版本
- nvm use [version] [arch] #切換制定的node版本和位數(shù)
- nvm root [path] #設(shè)置和查看root路徑
三、使用fnm命令安裝
# installs fnm (Fast Node Manager)
curl -fsSL https://fnm.vercel.app/install | bash# download and install Node.js
fnm use --install-if-missing 20# verifies the right Node.js version is in the environment
node -v # should print `v20.15.1`# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
相關(guān)命令
- fnm install #安裝指定版本node
- fnm install --lts #安裝LTS版本
- fnm uninstall #卸載指定版本
- fnm uninstall #卸載指定別名node同時刪除別名
- fnm use <version|alias-name> #使用指定版本node
- fnm alias #設(shè)置別名
- fnm unalias #取消別名
- fnm default #設(shè)置默認版本號