美文网首页
nvm安装(Mac篇)

nvm安装(Mac篇)

作者: 时光已翩然轻擦 | 来源:发表于2020-09-18 15:45 被阅读0次

MacOS下nvm的安装

版本记录:
2020.09.18 初版
2020.09.19 解决环境变量添加后,每次打开都需要重新source .bash_profile的问题

一、使用curl安装的步骤

1. 安装命令:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

2. 可能遇到的问题:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
image.png
  • 此问题的解决方案请参照一下这篇文章:

《curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused》

3. 安装:

image.png

4.检查是否安装成功

关闭再打开终端,输入

$ nvm --version

5. 可能遇到的问题

zsh: command not found: nvm

6. 解决问题5的步骤:

① 再次安装,提示已经安装了nvm(不用执行)
image.png
username@usernamedeMacBook-Pro ~ % curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13527  100 13527    0     0   9946      0  0:00:01  0:00:01 --:--:--  9939
=> nvm is already installed in /Users/username/.nvm, trying to update using git
=> => Compressing and cleaning up git repository

=> nvm source string already in /Users/username/.bash_profile
=> bash_completion source string already in /Users/username/.bash_profile
npm ERR! error in /usr/local/lib/node_modules/egret: ENOENT: no such file or directory, open '/usr/local/lib/node_modules/egret/package.json'
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:

/usr/local/lib
├── cnpm@6.1.1
├──  error: ENOENT: no such file or directory, open '/usr/local/lib/node_modules/egret/package.json
├── hexo-cli@4.2.0
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` Nodes), you can remove them from the system Node as follows:

     $ nvm use system
     $ npm uninstall -g a_module

=> Close and reopen your terminal to start using nvm or run the following to use it now:

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_completion

② 配置.bash_profile(环境变量)
# 进入当前用户的home目录
$ cd ~/
# 创建. bash_profile文件
$ touch .bash_profile 
# 创建. bash_profile文件
$ open .bash_profile 

在打开的记事本中加入

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh

③ 使加入的环境变量生效(很重要🌝)

source .bash_profile

④ 输入nvm --version 检查是否生效

image.png

这里已经显示安装的nvm版本了,说明安装成功啦~~~😆

😏你以为到这里就结束了吗?当然没有!!还是有可能出现以下问题:

环境变量添加后,每次打开都需要重新 source .bash_profile 才能使nvm生效,否则依然提示 zsh: command not found: nvm

⑤ 在.zshrc中添加环境变量

  • 在通过终端在记事本中打开.zshrc
# 注意是在当前用户的home目录
$ open .zshrc
  • 在.zshrc文件末尾处添加以下环境变量:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
  • 关闭记事本后,在终端中重新启动.zshrc配置
$ source .zshrc
  • 这样,以后每次新打开一个bash,nvm都会被自动添加到环境变量中了。

二、参考资料

相关文章

  • 2018-07-24

    mac 安装 nvm https://github.com/creationix/nvm

  • node版本管理器(含mac和windows)

    mac nvm 一. 安装NVM(前提是你安装了homebrew) $ brew install nvm 二.在s...

  • Mac 下 NVM 的安装与使用

    Mac 下 NVM 的安装与使用 安装 nvm 安装 注意后面的“v0.33.8”这是nvm的版本号 验证 nvm...

  • React | nvm 安装 Node.js (Mac OS)

    React | nvm 安装 Node.js (Mac OS) React | nvm 安装 Node.js (M...

  • Mac 安装nvm

    Nvm安装成功后,使用nvm命令却提示command not found,mac终端解决办法如下: 安装nvm 进...

  • nvm安装(Mac篇)

    MacOS下nvm的安装 版本记录:2020.09.18 初版2020.09.19 解决环境变量添加后,每次打开都...

  • Mac安装nvm的坑

    Mac机上安装nvm遇到的坑--nvm command not found nvm安装成功后,但命令不可用(com...

  • Mac 安装nvm

    brew安装nvm nvm是nodejs版本管理器,在Mac下可方便安装多版本的nodejs。 nvm命令

  • Mac 安装nvm

    搜了一圈如何安装nvm,此文档只记录mac 安装nvm的一次经历。 安装列表: 1、brew 2、zsh(Mac系...

  • Mac安装nodejs环境

    Mac安装nodejs环境 安装流程 1、github搜索nvm,进入项目 2、安装nvm 3、根据提示执行命令l...

网友评论

      本文标题:nvm安装(Mac篇)

      本文链接:https://www.haomeiwen.com/subject/wzllyktx.html