安装 【nvm】 马克布克
mac 安装 nvm 比较简单
- 1、确保之前没装node或已经卸载干净
- 2、拉取github上的镜像、安装
- 3、配置镜像源、切换版本
1、安装
从git上下载nvm
git clone https://github.com/nvm-sh/nvm.git
这里有下好的一份nvm20240318220531.zip
拉下来后 cd 进去nvm的目录 执行install.sh
文件等待安装完成。
2、配置
环境变量
找到bash_profile目录
vim ~/.bash_profile
添加下面配置
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# This loads nvm bash_completio
完成后就可以使用nvm -v查看版本了。
不过当我们重启终端,再次执行nvm -v查看版本的时候,发现报错:zsh:commond not found:nvm
这时候需要配置.zshrc文件。
配置.zshrc文件
找到.zshrc目录
open ~/.zshrc
双击打开,到文件最后添加
source ~/.bash_profile
保存后,发现上面的问题解决了。
配置镜像
设置node
vim ~/.bash_profile
// 加入以下配置文件
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
// 让设置生效
source ~/.bashrc
设置npm
npm config set registry https://registry.npm.taobao.org
也可以通过打开用户目录下的.npmrc,在文件中添加如下内容的方式进行设置:
registry=https://registry.npm.taobao.org
命令
nvm ls【列出安装版本】
nvm ls-remote 【列出所有版本】
nvm install Vxx 【安装某个版本】
nvm use Vxx 【切换到某个版本】
nvm uninstall Vxx 【删除版本】