Mac安装nvm
如默
撰写于 2023年 03月 02 日

说明

刚刚买了Mac mini,配置了一下环境,正好需要安装node,记录一下

步骤

本文使用brew安装,确保已经安装了brew包管理工具,若未安装,请参考:

这里先记录一下nvm官网,安装执行:

brew install nvm

安装成功会显示如下内容:

==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api/formul
######################################################################## 100.0%
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api/cask.j
######################################################################## 100.0%
==> Fetching nvm
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/nvm-0.39.3
######################################################################## 100.0%
==> Pouring nvm-0.39.3.all.bottle.tar.gz
==> Caveats
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.

You should create NVM's working directory if it doesn't exist:
  mkdir ~/.nvm

Add the following to your shell profile e.g. ~/.profile or ~/.zshrc:
  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/Cellar/nvm/0.39.3 will destroy any nvm-installed Node installations
upon upgrade/reinstall.

Type `nvm help` for further information.
==> Summary
🍺  /opt/homebrew/Cellar/nvm/0.39.3: 9 files, 190.5KB
==> Running `brew cleanup nvm`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

根据上面的提示,将下面的内容添加到.zprofile文件

  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

添加完执行source .zprofile

此时,就安装好了,下面列出常用的命令

Example:
  nvm install 8.0.0                     Install a specific version number
  nvm use 8.0                           Use the latest available 8.0.x release
  nvm run 6.10.3 app.js                 Run app.js using node 6.10.3
  nvm exec 4.8.3 node app.js            Run `node app.js` with the PATH pointing to node 4.8.3
  nvm alias default 8.1.0               Set default node version on a shell
  nvm alias default node                Always default to the latest available node version on a shell

  nvm install node                      Install the latest available version
  nvm use node                          Use the latest version
  nvm install --lts                     Install the latest LTS version
  nvm use --lts                         Use the latest LTS version

  nvm set-colors cgYmW                  Set text colors to cyan, green, bold yellow, magenta, and white

国外的node有些慢,可以替换成国内的地址,修改国内源,执行:

export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node

这样设置之后,nodejs可以从国内镜像地址下载,但是npm不是,需要设置一下才可以

参考nodejs的设置,很多人可能以为npm是这样设置的:export NVM_NPM_REGISTRY=https://registry.npm.taobao.org,亲测无效

正确的设置方法是直接执行:

npm config set registry https://registry.npmmirror.com

这样就好了,全局都是这个地址,不需要每个版本的nodejs都单独设置

查看npm地址命令如下:

npm config get registry

通过这个命令可以验证

Mac安装nvm

温馨提示:

本文最后更新于2023年03月02日,已超过416天没有更新,若内容或图片失效,请留言反馈。

说明

刚刚买了Mac mini,配置了一下环境,正好需要安装node,记录一下

步骤

本文使用brew安装,确保已经安装了brew包管理工具,若未安装,请参考:

这里先记录一下nvm官网,安装执行:

brew install nvm

安装成功会显示如下内容:

==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api/formul
######################################################################## 100.0%
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api/cask.j
######################################################################## 100.0%
==> Fetching nvm
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/nvm-0.39.3
######################################################################## 100.0%
==> Pouring nvm-0.39.3.all.bottle.tar.gz
==> Caveats
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.

You should create NVM's working directory if it doesn't exist:
  mkdir ~/.nvm

Add the following to your shell profile e.g. ~/.profile or ~/.zshrc:
  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/Cellar/nvm/0.39.3 will destroy any nvm-installed Node installations
upon upgrade/reinstall.

Type `nvm help` for further information.
==> Summary
🍺  /opt/homebrew/Cellar/nvm/0.39.3: 9 files, 190.5KB
==> Running `brew cleanup nvm`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

根据上面的提示,将下面的内容添加到.zprofile文件

  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

添加完执行source .zprofile

此时,就安装好了,下面列出常用的命令

Example:
  nvm install 8.0.0                     Install a specific version number
  nvm use 8.0                           Use the latest available 8.0.x release
  nvm run 6.10.3 app.js                 Run app.js using node 6.10.3
  nvm exec 4.8.3 node app.js            Run `node app.js` with the PATH pointing to node 4.8.3
  nvm alias default 8.1.0               Set default node version on a shell
  nvm alias default node                Always default to the latest available node version on a shell

  nvm install node                      Install the latest available version
  nvm use node                          Use the latest version
  nvm install --lts                     Install the latest LTS version
  nvm use --lts                         Use the latest LTS version

  nvm set-colors cgYmW                  Set text colors to cyan, green, bold yellow, magenta, and white

国外的node有些慢,可以替换成国内的地址,修改国内源,执行:

export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node

这样设置之后,nodejs可以从国内镜像地址下载,但是npm不是,需要设置一下才可以

参考nodejs的设置,很多人可能以为npm是这样设置的:export NVM_NPM_REGISTRY=https://registry.npm.taobao.org,亲测无效

正确的设置方法是直接执行:

npm config set registry https://registry.npmmirror.com

这样就好了,全局都是这个地址,不需要每个版本的nodejs都单独设置

查看npm地址命令如下:

npm config get registry

通过这个命令可以验证


那年今日
03月
02日
下一篇
MacOS更新Git
赞 (0)

猜您想看

  • PotPlayer使用电视直播源

    由于央视影音软件有很多的广告,也经常遇到各种bug,加上最近发现`PotPlayer`可以看斗鱼等直播,遂找一些电视直播源进行观看,特此记录。

    2020年11月22日
  • 七夕特供,一行代码写爱心~给某些人一点帮助

    七夕到了,有些人没有准备礼物,让我弄个东西,正好想起来以前看到的表白代码,记录一下

    2022年08月04日
  • Mac安装nvm

    刚刚买了Mac mini,配置了一下环境,正好需要安装node,记录一下

    2023年03月02日
  • MacOS配置homebrew

    前两天买的Mac mini到货了,正好需要配置环境,折腾了一下,特此记录。

    2023年03月02日
  • MacOS更新Git

    最近使用Mac电脑,发现Git不知道怎么升级,查了一下,特此记录

    2023年03月05日
  • oneindex搭建网盘

    本文介绍oneindex程序使用方法

    2019年03月13日

评论区(暂无评论)

这里空空如也,快来评论吧~

我要评论

Vaptcha 初始化中...