【ubuntu 18.04】安裝node的三種方式


1. 直接使用ubuntu軟件源安裝

sudo apt update
sudo apt install nodejs npm
nodejs --version
v10.19.0
npm -v

2. 從nodesource安裝nodejs和npm

# 安裝倉庫
https://github.com/nodesource/distributions

Installation instructions

Node.js v17.x:

 
         
# Using Ubuntu curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -fsSL https://deb.nodesource.com/setup_17.x | bash - apt-get install -y nodejs
 
         

Node.js v16.x:

 
         
# Using Ubuntu curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -fsSL https://deb.nodesource.com/setup_16.x | bash - apt-get install -y nodejs
 
         

Node.js v14.x:

 
         
# Using Ubuntu curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -fsSL https://deb.nodesource.com/setup_14.x | bash - apt-get install -y nodejs
 
         

Node.js v12.x:

 
         
# Using Ubuntu curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -fsSL https://deb.nodesource.com/setup_12.x | bash - apt-get install -y nodejs
 
         

Node.js LTS (v16.x):

 
         
# Using Ubuntu curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - apt-get install -y nodejs
 
         

Node.js Current (v17.x):

 
         
# Using Ubuntu curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash - sudo apt-get install -y nodejs # Using Debian, as root curl -fsSL https://deb.nodesource.com/setup_current.x | bash - apt-get install -y nodejs
 
         

Optional: install build tools

 
         

To compile and install native addons from npm you may also need to install build tools:

 
         
# use `sudo` on Ubuntu or run this as root on debian apt-get install -y build-essential

3. nvm安裝

# 通過腳本安裝
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
vim .bashrc
# 添加如下代碼
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# 保存退出后,執行下面命令讓配置生效
source .bashrc
master@master:~$ nvm -v
0.39.0

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM