折腾:
需要Nodejs的版本大于8才能继续用VuePress
而此处Mac本地nodejs版本是:
<code>➜ vuePress node --version v5.4.1 </code>
所以要去mac中升级node的版本
nodejs 版本查看
去下载最新版本
Latest LTS Version: 8.11.2 (includes npm 5.6.0)
https://nodejs.org/dist/v8.11.2/node-v8.11.2.pkg
This package will install:
• Node.js v8.11.2 to /usr/local/bin/node
• npm v5.6.0 to /usr/local/bin/npm
This package has installed:
• Node.js v8.11.2 to /usr/local/bin/node
• npm v5.6.0 to /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
结果重启终端后版本依旧是旧的5.4.1的,去看看:
<code>➜ vuePress echo $PATH /usr/local/mysql/bin:/Users/crifan/Library/Python/2.7/bin:/Users/crifan/Library/Python/3.6/bin:/Users/crifan/.nvm/versions/node/v5.4.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin ➜ vuePress ll /Users/crifan/.nvm/versions/node/v5.4.1/bin total 46184 -rwxr-xr-x 1 crifan staff 23M 1 13 2016 node lrwxr-xr-x 1 crifan staff 38B 1 13 2016 npm -> ../lib/node_modules/npm/bin/npm-cli.js lrwxr-xr-x 1 crifan staff 45B 1 14 2016 react-native -> ../lib/node_modules/react-native-cli/index.js ➜ vuePress cat ~/.bashrc export NVM_DIR="/Users/crifan/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm #export PATH="/Users/crifan/Library/Python/2.7/bin:/Users/crifan/Library/Python/3.6/bin:$PATH" export PATH="/usr/local/mysql/bin:/Users/crifan/Library/Python/2.7/bin:/Users/crifan/Library/Python/3.6/bin:$PATH" ➜ vuePress cat ~/.bash_profile [ -r ~/.bashrc ] && source ~/.bashrc # added by Anaconda2 5.0.1 installer # export PATH="/Users/crifan/anaconda2/bin:$PATH" ➜ vuePress ll /usr/local/bin/node -rwxr-xr-x 1 root wheel 34M 5 16 02:58 /usr/local/bin/node ➜ vuePress /usr/local/bin/node --version v8.11.2 ➜ vuePress /Users/crifan/.nvm/versions/node/v5.4.1/bin/node --version v5.4.1 ➜ vuePres </code>
很明显,是由于之前不知道哪里,加了:
/Users/crifan/.nvm/versions/node/v5.4.1/bin
在
/usr/local/bin/
之前,导致先识别了前面的node v5.4.1的
但是倒是哪里加出来的:
/Users/crifan/.nvm/versions/node
不清楚。
去搜搜看:
nodejs /Users/ .nvm/versions/node
nodejs .nvm/versions/node
Installing Multiple Versions of Node.js Using nvm — SitePoint
使用 nvm 管理不同版本的 node 与 npm | bubkoo
是之前不知道啥时候安装了nvm?
去看看现在有哪些版本了?
<code>➜ vuePress nvm ls -> v5.4.1 system default -> node (-> v5.4.1) node -> stable (-> v5.4.1) (default) stable -> 5.4 (-> v5.4.1) (default) iojs -> N/A (default) </code>
然后去安装,发现果然安装了,相对比较新的10的版本的node,然后也更新了path,可以找到最新的node了:
<code>➜ vuePress nvm install node Downloading https://nodejs.org/dist/v10.4.0/node-v10.4.0-darwin-x64.tar.gz... ######################################################################## 100.0% WARNING: checksums are currently disabled for node.js v4.0 and later Now using node v10.4.0 (npm v6.1.0) ➜ vuePress nvm ls v5.4.1 -> v10.4.0 system default -> node (-> v10.4.0) node -> stable (-> v10.4.0) (default) stable -> 10.4 (-> v10.4.0) (default) iojs -> N/A (default) ➜ vuePress echo $PATH /Users/crifan/.nvm/versions/node/v10.4.0/bin:/usr/local/mysql/bin:/Users/crifan/Library/Python/2.7/bin:/Users/crifan/Library/Python/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin ➜ vuePress node --version v10.4.0 ➜ vuePress which node /Users/crifan/.nvm/versions/node/v10.4.0/bin/node </code>
【总结】
此处mac中之前不知何时已经安装了nvm去管理node了。
之前安装旧版本是v5.4.1的node
现在通过:
<code>nvm install node </code>
即可安装最新版本node,然后可以通过:
<code>node —version which node echo $PATH </code>
知道最新版本,已经修改后的PATH。
转载请注明:在路上 » 【已解决】Mac中升级Node到最新版本