当前位置:   article > 正文

MAC:homebrew安装nvm及node_brew 安装node16

brew 安装node16

一、安装nvm

终端输入:

brew install nvm

安装完成后会出现提示:

You should create NVM's working directory if it doesn't exist:

  mkdir ~/.nvm

Add the following to ~/.zshrc or your desired shell

configuration file:

  export NVM_DIR="$HOME/.nvm"

  [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm

  [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

You can set $NVM_DIR to any location, but leaving it unchanged from

/opt/homebrew/opt/nvm will destroy any nvm-installed Node installations

upon upgrade/reinstall.

Type `nvm help` for further information.

根据提示输入创建nvm目录:

mkdir ~/.nvm

 编辑 ~/.zshrc 配置文件

①法一:直接在终端编辑(:wq 保存并退出):

vi ~/.zshrc

②法二:找到对应的文件夹(更方便) 

在 ~/.zshrc 配置文件后添加如下内容

  1. export NVM_DIR="$HOME/.nvm"
  2. [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
  3. [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion

使用 source 命令使配置生效

source ~/.zshrc

查看配置是否生效

echo $NVM_DIR

查看帮助手册

nvm -help

Note:

  to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)

删除卸载nvm只需要移除$NVM_DIR文件夹,一般是~/.nvm

查看版本

nvm -v

nvm ls-remote // 查看所有的node可用版本 

二、安装node 

安装指定版本的node

  1. nvm install 版本号
  2. node -v
  3. npm -v

淘宝镜像

npm config set registry https://registry.npm.taobao.org

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/847598
推荐阅读
相关标签
  

闽ICP备14008679号