mac 安裝node
- 首先安裝 macOS 不可或缺的套件管理器:Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
把這段命令放到終端運(yùn)行符隙,然后等待成功
$ brew install nvm
安裝成功之后....
- 打開
.bash_profile
文件
$ cd ~
$ vim .bash_profile
復(fù)制下面命令到.bash_profile
文件并保存退出(按esc鍵 輸入 :wq 最后enter鍵)
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
- 最后source一下
$ source .bash_profile
這樣就安裝完了nvm。
$ nvm ls-remote 查看node可用版本
$ nvm install xxx 下載你想要的版本
$ nvm use xxx 使用指定版本的node
$ nvm alias default xxx 每次啟動終端都使用該版本的node
- 檢測一下是否安裝成功
$ node -v
有木有卡儒?
如果有
- 我們再最后測試一下
touch 一個(gè) index.js
// 導(dǎo)入http模塊
const http = require('http');
// 通過createServer 能快速的創(chuàng)建一個(gè)HTTPserver
const server = http.createServer(function(req, res){
// 在回調(diào)函數(shù)中有2個(gè)參數(shù),req就是請求對象., res相應(yīng)對象
res.end('install to ok le ');
});
// 啟動并監(jiān)聽3000端口,一旦監(jiān)聽成功就回調(diào)閉包
server.listen(3000, '127.0.0.1', function(){
console.log('server listen 3000 at port');
});
執(zhí)行
$ node index.js
用瀏覽器打開http://localhost:3000 C鄞小H啊!
有木有G6凇爸黄!
.
.
.
.
說完了安裝。揭鳞。接下來卸載了
mac 卸載node
- brew 安裝的node 炕贵,命令卸載
$ brew uninstall node
接下來就是檢查各種 local、lib野崇、include 文件夾称开,刪除名字含有node和node_modules的文件包含npm,刪除命令
sudo rm -rf 文件路徑
比如 $ sudo rm -rf /usr/local/lib/node