"Close and reopen your terminal to start using nvm" not working - bash

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
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:
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

Related

zsh compinit: insecure directories, run compaudit for list

I get this when I tre to run the terminal on my mac:
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]? y
Suggested answers like this are of no use to me as they all involve running commands which I'm not currently able to do. How do I resolve this?
Ths is my .zshrc:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH="$HOME/.jenv/bin:$PATH:/Users/paulcarron/Apache/apache-maven-3.8.1/bin"
eval "$(jenv init -)"
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
source ~/.bash_profile
.bashrc:
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
eval "$(jenv init -)"
[ -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
if [ -r ~/.zshrc ]; then
source ~/.zshrc
fi
You have a created an infinite loop in your dotfiles. Your .zshrc sources your .bashrc, which sources your .zshrc, ad infinitum.
Additionally, when you source "$NVM_DIR/bash_completion" from zsh, it for some strange reason calls compinit. (This is something that nvm should not do.)
So, there you have it: Together, you’ve created yourself infinite compinits.
Moral of the story: It’s already a bad idea to source .bashrc from .zshrc, or vice versa, but doing it in both directions is even worse.
Solution: Don’t do that and remove the offending lines from your dotfiles.

nvm on MacOS init says: zsh compinit: insecure directories, run compaudit for list

I have just installed and configures nvm (https://github.com/nvm-sh/nvm)
on macOS
as (in .zshrc)
export NVM_DIR="$HOME/.nvm"
export PATH=$PATH:$NVM_DIR
[ -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
But every new Shell window or tab now warns about insecure directories
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?
compinit: initialization aborted
complete:13: command not found: compdef
What to do with that?
More info
MacOS Catalina
using default zshell
nvm -v
0.38.0
What worked for me was adding this line to my .zshrc file
export ZSH_DISABLE_COMPFIX=true

/Users/chingun/.zshrc:source:116: no such file or directory: /usr/local/opt/nvm/nvm.shexport

The following error occurs when I open my terminal:
Last login: Fri Jun 18 11:10:15 on ttys000
/Users/chingun/.zshrc:source:116: no such file or directory: /usr/local/opt/nvm/nvm.shexport
Terminal Picture 1
Just to clarify deepakchethan answer, you are exporting another path in your .zshrc file and there needs to be a space before that path is exported like below.
You probably have this:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"export PATH="/usr/local/opt/{another path}:$PATH"
You need to have this:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" export PATH="/usr/local/opt/{another path}:$PATH"
Notice there is no space before the export PATH= and therefore it is being concatenated. Took a while for me to notice this also.
You have a typo in the .zshrc file. Open the file /Users/chingun/.zshrc and in the line 116 you need to change the file path of nvm.sh from /usr/local/opt/nvm/nvm.shexport to /usr/local/opt/nvm/nvm.sh

React-Native env: node: No such file or directory

I'm getting the following build error when compiling my react-native project in Xcode env: node: No such file or directory
Not sure whats causing it?
Node v8.9.4
React-Native v0.50.4
NPM v5.6.0
And I'm using nvm
if you are using nvm do
sudo ln -s "$(which node)" /usr/local/bin/node
this will link current nvm to your usr local and next time Xcode will find the correct node path and version
Xcode have some issues finding node from nvm, try this inside the script that throws the error:
# Setup nvm and set node
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
. "$(brew --prefix nvm)/nvm.sh"
fi
[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
$NODE_BINARY ../node_modules/#sentry/cli/bin/sentry-cli upload-dsym
Here is one of the solutions for this error if you're using nvm and sentry: https://docs.sentry.io/clients/react-native/manual-setup/#using-node-with-nvm
In my case, this was related to an old sentry configuration and the fact that I use nvm.
Following https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/
you should be able to execute ln -s $(which node) /usr/local/bin/node and get it fixed
Add this at the top of the script that's failing (in Project -> build phases):
. ~/.nvm/nvm.sh
The solution I used documented here, was to create a script at /usr/local/bin/node that calls nvm
#!/usr/bin/env sh
# Use the version of node specified in .nvmrc to run the supplied command
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm
nvm_rc_version > /dev/null 2> /dev/null
HAS_NVM_RC=$?
if [[ "$HAS_NVM_RC" == "0" ]] ; then
nvm run $*
else
nvm run default $*
fi
exit $?

Use .bash_profile and .bashrc as one

I have the following code in my .bash_profile:
1 [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
2
3 export NVM_DIR="$HOME/.nvm"
4 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
5 [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
And the following in my .bashrc:
1 # Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
2 export PATH="$PATH:$HOME/.rvm/bin"
Is there an way to avoid one of the files? I mean, only use one as both?
Thank you.
just put following code in .bash_profile file. Basically source the .bashrc file in .bash_profile.
source .bashrc

Resources