mac 安裝node
- 首先安裝 macOS 不可或缺的套件管理器:Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
把這段命令放到終端運(yùn)行,然后等待成功
$ brew install nvm
安裝成功之后....
- 打開(kāi)
.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 每次啟動(dòng)終端都使用該版本的node
- 檢測(cè)一下是否安裝成功
$ node -v
有木有?
如果有
- 我們?cè)僮詈鬁y(cè)試一下
touch 一個(gè) index.js
// 導(dǎo)入http模塊
const http = require('http');
// 通過(guò)createServer 能快速的創(chuàng)建一個(gè)HTTPserver
const server = http.createServer(function(req, res){
// 在回調(diào)函數(shù)中有2個(gè)參數(shù),req就是請(qǐng)求對(duì)象., res相應(yīng)對(duì)象
res.end('install to ok le ');
});
// 啟動(dòng)并監(jiān)聽(tīng)3000端口,一旦監(jiān)聽(tīng)成功就回調(diào)閉包
server.listen(3000, '127.0.0.1', function(){
console.log('server listen 3000 at port');
});
執(zhí)行
$ node index.js
用瀏覽器打開(kāi)http://localhost:3000 ?。?!
有木有??!

6868A755-0E7C-44CE-8FD4-FCABB18A054A.png
.
.
.
.
說(shuō)完了安裝。。接下來(lái)卸載了
mac 卸載node
- brew 安裝的node ,命令卸載
$ brew uninstall node
接下來(lái)就是檢查各種 local、lib、include 文件夾,刪除名字含有node和node_modules的文件包含npm,刪除命令
sudo rm -rf 文件路徑
比如 $ sudo rm -rf /usr/local/lib/node