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
Related
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.
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
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
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
The only way my .bashrc and .bashprofile are recognized by OSX is if I specify in my terminal's preferences for the file to be targeted upon boot. Is there a reason why they're not working like they should be?
Here's the inside of my .bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" #
Load RVM into a shell session *as a function*
#Add RVM to PATH for scripting. Make sure this is the last PATH
variable change.
export PATH="$PATH:$HOME/.rvm/bin"
smiley () { echo -e ":\\$(($??50:51))"; }
export PS1="\h\$(smiley) \e[30;1m\w\e[0m\n\$ "
Inside of .bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" #
Load RVM into a shell session *as a function*
# Add RVM to PATH for scripting. Make sure this is the last PATH n .
variable change.
export PATH="$PATH:$HOME/.rvm/bin"
alias b='cd ..'
Any help would be appreciated! Thanks!
In OSX, all sessions are login sessions and will not source $HOME/.bashrc, they will source $HOME/.profile or $HOME/.bash_profile. So put the following in your .bash_profile
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi