How to Fix "You have $NVM_DIR set to "/Users/yourname/.nvm", but that directory does not exist."
I’ll introduce how to fix the issue where nvm cannot be installed and displays the message You have $NVM_DIR set to “/Users/yourname/.nvm”, but that directory does not exist.
From Install & Update script | creationix/nvm: Node Version Manager, even when running the nvm installation script as follows, the message You have $NVM_DIR set to “/Users/yourname/.nvm”, but that directory does not exist. Check your profile files and environment. was displayed and it wasn’t installed.
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13226 100 13226 0 0 113k 0 --:--:-- --:--:-- --:--:-- 114k
You have $NVM_DIR set to "/Users/yourname/.nvm", but that directory does not exist. Check your profile files and environment.
The cause was that a value was set in the environment variable NVM_DIR.
$ echo $NVM_DIR
/Users/yourname/.nvm
Empty the environment variable NVM_DIR.
NVM_DIR=
$ echo $NVM_DIR
When I ran the nvm installation script again, I was able to successfully install nvm.
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13226 100 13226 0 0 52131 0 --:--:-- --:--:-- --:--:-- 52276
=> Downloading nvm from git to '/Users/yourname/.nvm'
=> Cloning into '/Users/yourname/.nvm'...
remote: Enumerating objects: 278, done.
remote: Counting objects: 100% (278/278), done.
remote: Compressing objects: 100% (249/249), done.
remote: Total 278 (delta 33), reused 93 (delta 16), pack-reused 0
Receiving objects: 100% (278/278), 142.36 KiB | 24.00 KiB/s, done.
Resolving deltas: 100% (33/33), done.
=> Compressing and cleaning up git repository
=> Appending nvm source string to /Users/yourname/.zshrc
=> Appending bash_completion source string to /Users/yourname/.zshrc
=> 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
That’s all from the Gemba on being troubled by not being able to install nvm.