I'm using a MacBook Air which has the new Apple M1 chip and I'm trying to install 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 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. 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
I have deleted the .bashrc file in the home directory and created a new one with the following content:
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.
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:
MacBook-Air-gignu:~ gignu$ nvm -v
0.37.2
But if I close the terminal and then reopen it, nvm is not installed anymore.
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:
source ~/.bashrc
My .bash_profile file now looks like this:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.