最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[未解决]Mac中安装NVM后无法运行

Mac crifan 5614浏览 0评论

[记录]折腾React Native

期间,

安装了nvm后,输出:

licrifandeMacBook-Pro:nodejs crifan$ pwd
/Users/crifan/dev/dev_src/nodejs
licrifandeMacBook-Pro:nodejs crifan$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7735  100  7735    0     0   4784      0  0:00:01  0:00:01 –:–:–  4783
=> Downloading nvm from git to ‘/Users/crifan/.nvm’
=> Cloning into ‘/Users/crifan/.nvm’…
remote: Counting objects: 4308, done.
remote: Total 4308 (delta 0), reused 0 (delta 0), pack-reused 4308
Receiving objects: 100% (4308/4308), 1.09 MiB | 149.00 KiB/s, done.
Resolving deltas: 100% (2520/2520), done.
Checking connectivity… done.
*
(HEAD detached at v0.30.1)
  master

=> Profile not found. Tried  (as defined in $PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
=> Create it (touch ) and run this script again
   OR
=> Append the following lines to the correct file yourself:

export NVM_DIR="/Users/crifan/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

=> Close and reopen your terminal to start using nvm

之后,去运行nvm:

licrifandeMacBook-Pro:nodejs crifan$ nvm install 5.0
-bash: nvm: command not found

搜:

mac Profile not found. Tried  (as defined in $PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile

-bash: nvm: command not found · Issue #576 · creationix/nvm

很明显是:

mac中没有对应的bash文件

搜:

mac create .bashrc

osx – How do I create a bash alias? – Stack Overflow

licrifandeMacBook-Pro:nodejs crifan$ cd ~
licrifandeMacBook-Pro:~ crifan$ pwd
/Users/crifan
licrifandeMacBook-Pro:~ crifan$ touch .bashrc
licrifandeMacBook-Pro:~ crifan$ cd ~
licrifandeMacBook-Pro:~ crifan$ ls
Applications Documents Library Music Public dev 微云同步盘
Desktop Downloads Movies Pictures StudioProjects ishot-1.png
licrifandeMacBook-Pro:~ crifan$ ls -la
total 760
drwxr-xr-x+  32 crifan  staff    1088  1 14 12:56 .
drwxr-xr-x    6 root    admin     204 10 22 10:23 ..
 …
-rw——-    1 crifan  staff    9263  1  6 14:11 .bash_history
drwxr-xr-x   72 crifan  staff    2448  1 14 12:51 .bash_sessions
-rw-r–r–    1 crifan  staff       0  1 14 12:56 .bashrc
 …
drwxr-xr-x    3 crifan  staff     102  9 18 21:12 .local
drwxr-xr-x   17 crifan  staff     578  1 14 12:49 .nvm
 …
licrifandeMacBook-Pro:~ crifan$

然后继续重新安装:

licrifandeMacBook-Pro:~ crifan$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7735  100  7735    0     0   4291      0  0:00:01  0:00:01 –:–:–  4290
=> nvm is already installed in /Users/crifan/.nvm, trying to update using git
=>
=> Appending source string to /Users/crifan/.bashrc
=> Close and reopen your terminal to start using nvm

但是关闭终端后重新运行nvm还是找不到:

licrifandeMacBook-Pro:~ crifan$ nvm
-bash: nvm: command not found
licrifandeMacBook-Pro:~ crifan$ cat ~/.bashrc

export NVM_DIR="/Users/crifan/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
licrifandeMacBook-Pro:~ crifan$


不过后来通过souce了一下:

. ~/.nvm/nvm.sh

就可以找到nvm了:

Last login: Thu Jan 14 13:00:10 on ttys000
licrifandeMacBook-Pro:~ crifan$ nvm
-bash: nvm: command not found
licrifandeMacBook-Pro:~ crifan$ cat ~/.bashrc

export NVM_DIR="/Users/crifan/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
licrifandeMacBook-Pro:~ crifan$ . ~/.nvm/nvm.sh
licrifandeMacBook-Pro:~ crifan$ nvm

Node Version Manager

Note: <version> refers to any version-like string nvm understands. This includes:
  – full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  – default (built-in) aliases: node, stable, unstable, iojs, system
  – custom aliases you define with `nvm alias foo`

Usage:
  nvm help                                  Show this message
  nvm –version                             Print out the latest released version of nvm
  nvm install [-s] <version>                Download and install a <version>, [-s] from source. Uses .nvmrc if available
    –reinstall-packages-from=<version>     When installing, reinstall packages installed in <node|iojs|node version number>
  nvm uninstall <version>                   Uninstall a version
  nvm use [–silent] <version>              Modify PATH to use <version>. Uses .nvmrc if available
  nvm exec [–silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available
  nvm run [–silent] <version> [<args>]     Run `node` on <version> with <args> as arguments. Uses .nvmrc if available
  nvm current                               Display currently activated version
  nvm ls                                    List installed versions
  nvm ls <version>                          List versions matching a given description
  nvm ls-remote                             List remote versions available for install
  nvm version <version>                     Resolve the given description to a single local version
  nvm version-remote <version>              Resolve the given description to a single remote version
  nvm deactivate                            Undo effects of `nvm` on current shell
  nvm alias [<pattern>]                     Show all aliases beginning with <pattern>
  nvm alias <name> <version>                Set an alias named <name> pointing to <version>
  nvm unalias <name>                        Deletes the alias named <name>
  nvm reinstall-packages <version>          Reinstall global `npm` packages contained in <version> to current version
  nvm unload                                Unload `nvm` from shell
  nvm which [<version>]                     Display path to installed node version. Uses .nvmrc if available

Example:
  nvm install v0.10.32                  Install a specific version number
  nvm use 0.10                          Use the latest available 0.10.x release
  nvm run 0.10.32 app.js                Run app.js using node v0.10.32
  nvm exec 0.10.32 node app.js          Run `node app.js` with the PATH pointing to node v0.10.32
  nvm alias default 0.10.32             Set default node version on a shell

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

licrifandeMacBook-Pro:~ crifan$


然后关闭终端,重启终端,还是无法直接使用nvm:

还是在source:

source ~/.nvm/nvm.sh

之后才能用。

算了:

删除nvm,重新安装试试:

licrifandeMacBook-Pro:~ crifan$ nvm
-bash: nvm: command not found
licrifandeMacBook-Pro:~ crifan$ rm ~/.nvm/
.git/            .travis.yml      README.markdown  nvm.sh
.gitattributes   CONTRIBUTING.md  bash_completion  package.json
.gitignore       LICENSE.md       install.sh       test/
.npmignore       Makefile         nvm-exec        
licrifandeMacBook-Pro:~ crifan$ rm -rf ~/.nvm/
licrifandeMacBook-Pro:~ crifan$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7735  100  7735    0     0   3413      0  0:00:02  0:00:02 –:–:–  3415
=> Downloading nvm from git to ‘/Users/crifan/.nvm’
=> Cloning into ‘/Users/crifan/.nvm’…
remote: Counting objects: 4308, done.
remote: Total 4308 (delta 0), reused 0 (delta 0), pack-reused 4308
Receiving objects: 100% (4308/4308), 1.09 MiB | 247.00 KiB/s, done.
Resolving deltas: 100% (2520/2520), done.
Checking connectivity… done.
*
(HEAD detached at v0.30.1)
  master

=> Source string already in /Users/crifan/.bashrc
=> Close and reopen your terminal to start using nvm
licrifandeMacBook-Pro:~ crifan$ source ~/.nvm/nvm.sh
licrifandeMacBook-Pro:~ crifan$ nvm

Node Version Manager

Note: <version> refers to any version-like string nvm understands. This includes:
  – full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  – default (built-in) aliases: node, stable, unstable, iojs, system

  – custom aliases you define with `nvm alias foo`

还是不行:

重启终端后,还是无法直接运行nvm。。。

算了:

抽空再去研究,如何才能确保:

重启终端后,输入nvm还能识别

-》估计是重启终端后,没有执行到.bashrc

转载请注明:在路上 » [未解决]Mac中安装NVM后无法运行

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 因为没有load: 输入: 2.export NVM_DIR="$HOME/.nvm" 3.[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
    loioce7年前 (2017-11-24)回复
92 queries in 0.229 seconds, using 22.15MB memory