Today was the 1st day of my coding bootcamp and they have us a script that installs all the development cli tools we are gonna use in class. I was using zsh before installing this script and node was working just fine. After running this script none of my previous node, homebrew or any other packages that this script installed works in zsh but they all work in bash. Is there anyway to fix this ?
On windows bash WSL I had to copy this from .bashrc to zshrc based on suggestion by AGDM, but not everything (like with source) or you get a ton of errors. I can finally run npm -v and the usual stuff like npm run start my react app from zsh in vscode.
# npm was not working
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
For node commands via terminal, like npm i <some-cool-npm-jam> --save-dev.
I copied the contents of .bashrc to .zshrc to run the node commands in zsh mode.
Worked flawlessly.
Related
When I run the command source $HOME/.zshrc on Jenkins shell, that runs on a MAC slave, I get the following error in the nvm initialisation:
nvm_err 'N/A: version "N/A -> N/A" is not yet installed.
nvm_err 'You need to run "nvm install N/A" to install it before using it.'
The error does not occurs on local machine, only on jenkins shell. The contents of the .zshrc that crashes is this:
# NVM
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
However, this is the script of the recommended initialisation of nvm, and it is added automatically on nvm installation. Anyone knows what may cause this problem?
I found this article that has an workaround to this problem. This worked for me. In resume, I had just to set the property +ex to make the shell ignore the immediate errors temporarily:
set +ex
source $HOME/.zshrc
set -ex
I have recently just started using wsl and zsh for dev purposes and I have tried to add the nvm through as a plugin in zsh through the ~/.zshrc file. I've added, saved and reloaded the terminal several times and tries the nvm command and it comes out with the 'zsh: command not found: nvm' error.
Any suggestions?
You can add nvm's loading script to ~/.zshrc. This instruction can be found on the readme.
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
You can test with:
which node
Hope this works :)
I'm using hyper terminal on Windows 10 with WSL(Windows Subsystem for Linux). I've got wsl to default to zsh but whenever I run npm or node i get the "zsh: command not found: node" or npm. To fix this i have to enter "bash" let the terminal switch to bash and then enter "zsh" to switch back. After that node and npm commands work.
Please help! I tried looking at existing posts but didn't find anything relating to this issue.
Thanks for your help in advance!
Just figured it out. Had to add the following in my .zshrc
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_comp$
Although this does make zsh take a long time to load initially.
os: macOS Sierra 10.12.6 (16G29)
terminal app: Hyper 1.3.3.1754
nvm: 0.33.2
I installed nvm, according to the instruction, sometime ago without issue. Recently, it and the commands it's responsible for —node and npm— stopped working.
nvm/npm/node command not found
I realized that this occurred because I recently switched my system default shell from bash to zsh —chsh -s /bin/zsh— without addressing the contents of ~/.bash_profile which is sourced by bash but not zsh.
The nvm install script
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
places the following in the appropriate config file —one of: ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.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
At time of install I used bash and that bit was placed in ~/.bash_profile. Coping that content over to ~/.zshrc got the commands working again.
I'm having trouble getting the Ruby Version Manager rvm to source from my Ubuntu 10.04 .profile. The code:
[[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"
...never does what I expect it to (i.e. give me the rvm program when I open a new shell or start a new session); but if I execute
source .profile
in a new shell after logging in, it works! Why will it work when I manually source it, but not automatically at login?
It would appear that Ubuntu handles it's logon scripts differently than most other linux distros
http://ubuntuforums.org/showpost.php?p=9127226&postcount=6
The above post has hints that GDM logins in Ubuntu don't process .bash_profile or .profile the way most other linux distros do. I have had to put the line loading RVM in the ~/.bashrc and that has not caused any problems yet.
Sourcing $HOME/.rvm assumes you have installed RVM a single user, specially, the user whose home directory is $HOME. Likely, on your Ubuntu system, RVM has been installed system wide, and thus you must source the RVM scripts as such:
In your .bashrc file add:
\# Set rvm path
[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"
before this line; this line will exit and not execute anything past it, which is fine for interactive logins, bit would be a problem is you are using non-interactive SSH logins for automation purposes.
\# If not running interactively, don't do anything
[ -z "$PS1" ] && return
The RVM installation page has a series of things to check to test the initialization of RVM. Read the "Troubleshooting your Install" section at the end of the RVM installation page.
Also, here's a description of how Bash reads its startup files which can help with this sort of problem.
I had a problem with Atom editor not picking up RVM environment and thus not finding rubocop command on Ubuntu 16.04. But the problem was not there when I started Atom from gnome terminal. What I've found was that RVM script ~/.rvm/scripts/rvm that you're supposed to be loading in your .profile has these lines at the beginning:
if
builtin test -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" -o -n "${KSH_VERSION:-}"
then
...
else
return 0
fi
Strangely, when executed at login, I've found $BASH_VERSION to be empty (while in gnome terminal it's sth like 4.3.46(1)-release), so the script would do early return leaving RVM not loaded properly. I tried to set BASH_VERSION to whatever and it worked fine.
Here is the complete code from my .profile that loads RVM:
local rvm_home="${HOME}/.rvm"
export PATH="$PATH:${rvm_home}/bin"
if [ -z "$BASH_VERSION" ]; then
export BASH_VERSION=4
fi
source "${rvm_home}/scripts/rvm"