最近要写 Vue 发现 Vue 要求的环境,和之前公司 RN 开发环境 Node 版本不匹配,怎么创建模板项目都是失败,一个个装组件还是失败,算了,不折腾了,老老实实装个特定版本 Node ,然后再装个最近版本 Node 吧;
首先查看本地设备安装的 Node 版本,命令如下:
$ which node
/usr/local/opt/node@10/bin/node
查看本地 node 版本,命令如下:
$ node --version
v10.23.1
本地配置文件(.bash_profile),配置项列表如下:
# Android SDK Path
export ANDROID_SDK=/Users/XXX/Library/Android/sdk
export ANDROID_SDK_ROOT=$ANDROID_SDK
export PATH=${PATH}:$ANDROID_SDK:$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools
export PATH=${PATH}:$ANDROID_SDK_ROOT
# Android NDK Path
# export ANDROID_NDK=/Users/XXX/Library/Android/sdk/ndk-bundle
export ANDROID_NDK=/Users/XXX/Library/Android/sdk/android-ndk-r10e
export PATH=${PATH}:$ANDROID_NDK
# Java Home Path
# export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=${PATH}:$JAVA_HOME:$JAVA_HOME/bin:$CLASSPATH
# Gradle Home Path
export Gradle_Home=/Applications/Android\ Studio.app/Contents/gradle/gradle-4.4
export PATH=${PATH}:$Gradle_Home/bin
# Anaconda Path
# export Anaconda=/usr/local/anaconda3
# export PATH=${PATH}:$Anaconda:$Anaconda/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# Node Path v10.23.1
export NODE_HOME=/usr/local/opt/node@10
export PATH=$NODE_HOME/bin:$PATH
export LDFLAGS="-L/usr/local/opt/node@10/lib"
export CPPFLAGS="-I/usr/local/opt/node@10/include"
# Homebrew Settings
export HOMEBREW_NO_AUTO_UPDATE=true
搜索一下,命令如下:
$ brew search node
==> Formulae
libbitcoin-node node-build node@12 nodebrew
llnode node-sass node@14 nodeenv
node node@10 ✔ node_exporter nodenv
==> Casks
nodebox nodeclipse
If you meant "node" specifically:
It was migrated from homebrew/cask to homebrew/core.
由于我已经安装了 node@10 版本的,现在我要安装 node(目前最新为 15.5.1) 版本的,命令如下:
$ brew install node
==> Downloading https://homebrew.bintray.com/bottles/node-15.5.1.catalina.bottle
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/bb48a61323732fd7dce43
######################################################################## 100.0%
==> Pouring node-15.5.1.catalina.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
/usr/local/Cellar/node/15.5.1: 3,291 files, 55.5MB
由于我安装的版本为 node@15 ,所以我需要切换一下环境变量,打开 ~/.bash_profile 文件,修改为如下:
具体请结合自己实际版本需求,建议 node LTS 版本;
# Node Path node@10
# export NODE_HOME=/usr/local/opt/node@10
# export PATH=$NODE_HOME/bin:$PATH
# export LDFLAGS="-L/usr/local/opt/node@10/lib"
# export CPPFLAGS="-I/usr/local/opt/node@10/include"
#
#
# Node Path node@15
export NODE_HOME=/usr/local/opt/node@15
export PATH=$NODE_HOME/bin:$PATH
export LDFLAGS="-L/usr/local/opt/node@15/lib"
export CPPFLAGS="-I/usr/local/opt/node@15/include"
此时保存文件,然后执行如下命令,使得配置生效:
$ source .bash_profile
此时,使用如下命令,验证一下:
$ node --version
v15.5.1
最后,如果想切回到 node@10 请放开上述配置文件中的注释段,把 node@15 的注释掉,在重新使得配置文件生效一下即可;
(完)