前言
Node.js 是運行在服務端的 JavaScript, 是基于 Chrome JavaScript V8 引擎建立的平臺。
1、下載最新的穩定版 v8.4.0 到本地
// 方法一:在服務器執行命令直接下載
wget https://nodejs.org/dist/v8.4.0/node-v8.4.0-linux-x64.tar.xz
//方法二:在官網上下載相關版本源碼后,上傳至服務器
http://nodejs.cn/download/
2、下載完成后, 將其解壓
tar xvJf node-v8.4.0-linux-x64.tar.xz
3、將解壓的 Node.js 目錄移動到 /usr/local 目錄下
mv node-v8.4.0-linux-x64 /usr/local/node-v8
4、添加node環境變量到 .bash_profile,是之能全局使用node命令
找到.bash_profile文件,并查看里面的內容 cat .bash_profile
如下:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
執行修改的命令:vi .bash_profile
后,執行i
開始編輯
將.bash_profile修改成:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export NODE_HOME=/usr/local/node-v6
export PATH=.:$NODE_HOME/bin:$PATH
如此就將node的環境變量添加好了
5、生效環境變量
source .bash_profile
6、測試是否安裝成功
node -v
npm -v
打印出版本號就說明安裝成功了