Nodejs安裝
Node.js 是什么?
Node.js® 是一個基於 Chrome V8 引擎 的 JavaScript 運行時環境。
1. 官網
2. 下載地址
3. 參考文檔
- 如何安裝 Node.js: http://nodejs.cn/learn/how-to-install-nodejs
4. 安裝步驟
4.1 Ubuntu 環境
參考文檔:https://github.com/nodesource/distributions/blob/master/README.md#debmanual
4.1.1 移除舊版本 PPA
# add-apt-repository may not be present on some Ubuntu releases:
# sudo apt-get install python-software-properties
sudo add-apt-repository -y -r ppa:chris-lea/node.js
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list
sudo rm -f /etc/apt/sources.list.d/chris-lea-node_js-*.list.save
4.1.2 添加 NodeSource package signing key
KEYRING=/usr/share/keyrings/nodesource.gpg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
# wget can also be used:
# wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | sudo tee "$KEYRING" >/dev/null
gpg --no-default-keyring --keyring "$KEYRING" --list-keys
4.1.3 添加期望版本 NodeSource repository
# Replace with the branch of Node.js or io.js you want to install: node_6.x, node_8.x, etc...
VERSION=node_8.x
# Replace with the keyring above, if different
KEYRING=/usr/share/keyrings/nodesource.gpg
# The below command will set this correctly, but if lsb_release isn't available, you can set it manually:
# - For Debian distributions: jessie, sid, etc...
# - For Ubuntu distributions: xenial, bionic, etc...
# - For Debian or Ubuntu derived distributions your best option is to use the codename corresponding to the upstream release your distribution is based off. This is an advanced scenario and unsupported if your distribution is not listed as supported per earlier in this README.
DISTRO="$(lsb_release -s -c)"
echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb-src [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
4.1.4 更新包列表並且安裝 Node.js
sudo apt-get update
sudo apt-get install nodejs
4.2 CentOS7 環境
4.2.1下載安裝包
安裝包下載地址:https://nodejs.org/zh-cn/download/

這里我選擇下載 Linux 64位版本

4.2.2 安裝包上傳到服務器
將 node-v16.13.0-linux-x64.tar.xz 上傳至服務器。
4.2.3 解壓安裝包
(1) 將 node-v16.13.0-linux-x64.tar.xz 解壓為 node-v16.13.0-linux-x64.tar
解壓命令:
xz -d node-v16.13.0-linux-x64.tar.xz
(2) 將 node-v16.13.0-linux-x64.tar 解壓
解壓命令:
tar -xvf node-v16.13.0-linux-x64.tar
4.2.4 驗證
## 切換到 安裝bin目錄下
cd /opt/nodejs/node-v16.13.0-linux-x64/bin
## 查看npm版本
./npm -v

4.3 windows7 環境
4.3.1下載安裝包
安裝包下載地址:https://nodejs.org/zh-cn/download/
選擇 Windows 安裝包 64 位版本。
我這里的版本是 node-v16.13.0-x64.msi
4.3.2 安裝
報錯,提示 版本不適合windows7:

經百度,13.14.0是支持win7 的最后版本是 ,下載地址:https://nodejs.org/download/release/v13.14.0/






4.3.3 驗證
打開 CMD 窗口,輸入 node -v :

安裝成功。
CMD 窗口,輸入 “npm install npm -g” 命令可安裝 npm。
5.使用 npm 安裝js 包
https://www.npmjs.com/ 可以搜索應該下載的js包
# 在項目路徑下安裝 jquery
npm install jquery

設置 npm 國內鏡像
# 設置 淘寶鏡像
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
# 恢復默認鏡像
npm config set registry https://registry.npmjs.org

沒有報錯,查看當前鏡像:
# 查看當前鏡像
npm get registry

4.3 Windows 11 環境
前面已經使用安裝包安裝了,這里采用免安裝方式安裝。
4.3.1 下載 Nodejs
安裝版本(64位):https://nodejs.org/dist/v18.15.0/node-v18.15.0-x64.msi
免安裝版本(64位):https://nodejs.org/dist/v18.15.0/node-v18.15.0-win-x64.zip
4.3.2 解壓 node-v18.15.0-win-x64.zip
將 node-v18.15.0-win-x64.zip 解壓到本地某個目錄。我這里解壓到本地:C:\work\soft\node-v18.15.0-win-x64
4.3.3 配置環境變量
將解壓目錄配置到環境變量:

然后將 NODEJS_HOME 配置到 PATH 中:


4.3.4 驗證
打開 CMD 窗口,輸入node -v 回車,輸出“v18.15.0” 即安裝完成。
