简体   繁体   English

“关闭并重新打开终端以开始使用 nvm”不起作用

[英]“Close and reopen your terminal to start using nvm” not working

I'm using a MacBook Air which has the new Apple M1 chip and I'm trying to install nvm.我正在使用配备新 Apple M1 芯片的 MacBook Air,我正在尝试安装 nvm。 First, I check whether it is already installed:首先,我检查它是否已经安装:

MacBook-Air-gignu:~ gignu$ nvm -v
-bash: nvm: command not found

It looks like it is not installed.好像没有安装。 So I try to install it like so:所以我尝试像这样安装它:

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

Now it tells me that nvm is already installed:现在它告诉我 nvm 已经安装:

=> nvm is already installed in /Users/gignu/.nvm, trying to update using git
=> => Compressing and cleaning up git repository

=> nvm source string already in /Users/gignu/.bash_profile
=> bash_completion source string already in /Users/gignu/.bash_profile
=> 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

Apparently, nvm is already installed and all I have to do is "close and reopen" my terminal.显然,nvm 已经安装,我所要做的就是“关闭并重新打开”我的终端。 But if I close the terminal, reopen it and type in nvm -v I get the same response as the first time: command not found但是如果我关闭终端,重新打开它并输入nvm -v我会得到与第一次相同的响应: command not found

What I've tried so far到目前为止我尝试过的

I have deleted the .bashrc file in the home directory and created a new one with the following content:我删除了主目录中的 .bashrc 文件,并创建了一个包含以下内容的新文件:

export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"

It didn't work.它没有用。

I have also done the same thing with different content:我也用不同的内容做了同样的事情:

NVM_DIR = "${XDG_CONFIG_HOME / - .$HOME /} NVM"
[-s"$NVM_DIR / nvm.sh"] && \. "$NVM_DIR / nvm.sh"#This will load nvm

And also with this:还有这个:

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

Nothing works, no matter if I put it in the .bashrc file or the .bash_profile file.没有任何作用,无论我是将它放在 .bashrc 文件还是 .bash_profile 文件中。

What works temporarily is executing the code from above in the terminal:暂时有效的是在终端中从上面执行代码:

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

Now when I check nvm, it's installed:现在,当我检查 nvm 时,它已安装:

MacBook-Air-gignu:~ gignu$ nvm -v
0.37.2

But if I close the terminal and then reopen it, nvm is not installed anymore.但是,如果我关闭终端然后重新打开它,则不再安装 nvm。

Thx in advance for your help!提前感谢您的帮助!

I found the solution!我找到了解决方案!

You have to put the following at the beginning of either your .bashrc file or your .bash_profile file:您必须将以下内容放在 .bashrc 文件或 .bash_profile 文件的开头:

source ~/.bashrc

My .bash_profile file now looks like this:我的 .bash_profile 文件现在看起来像这样:

source ~/.bashrc
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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM