Can't run nvm of Fish shell on Mac [duplicate] - nvm

This question already has an answer here:
How to manage my node version using Fish Shell
(1 answer)
Closed 13 days ago.
I have installed Fish shell via Brew.
According to the instructions given on the terminal while installing Fish, I added:
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
to
~/.config/fish/config.fish
and to
~/.zprofile
On normal terminal I can run nvm however on fish it says fish: Unknown command: nvm
If I do source ~/.config/fish/config.fish I get:
/opt/homebrew/Cellar/nvm/0.39.3/libexec/nvm.sh (line 386): Unexpected ')' found, expecting '}'
*[!/]*/)
^
from sourcing file /opt/homebrew/Cellar/nvm/0.39.3/libexec/nvm.sh
called on line 3 of file /opt/homebrew/opt/nvm/nvm.sh
from sourcing file /opt/homebrew/opt/nvm/nvm.sh
called on line 6 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
.: Error while reading file '/opt/homebrew/Cellar/nvm/0.39.3/libexec/nvm.sh'
/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm (line 5): Missing end to balance this if statement
if ! command -v nvm &> /dev/null; then
^^
from sourcing file /opt/homebrew/opt/nvm/etc/bash_completion.d/nvm
called on line 7 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
.: Error while reading file '/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm'
What can I do to run nvm on Fish?

What the error message tells you is that nvm is not a fish script.
nvm is written as a posix-compatible shell script and fish is intentionally not posix-compatible.
This bit here:
\. "/opt/homebrew/opt/nvm/nvm.sh"
Tells the shell to "source" nvm.sh, meaning to run it in the current shell. That won't work because fish isn't a posix shell.
You'll have to use either another version manager like nvm.fish or use a posix-to-fish shim like bass and do something like its nvm instructions:
bass source ~/.nvm/nvm.sh --no-use ';' nvm use iojs

Related

Node reverts to old version and NVM disappears when I close terminal and restart

Issue
I have installed NVM. Each time I close the terminal and open it back up, NVM disappears and my node version rolls back from 14 to 12.
Every time I open my terminal back up, I notice the node version rolls back. I try to use nvm, and will get bash: nvm: command not found. I have to run this script again to get it working every time.
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
I noticed the meta description when you google NVM says it's designed to be used per-user and invoked per shell. However, the setup article linked in the first SO post below mentioned installing, killing the terminal, and opening it back up with nvm still being loaded.
Anyone know what I can do so that I don't have to reinstall nvm every time I open the terminal?
Steps taken to resolve
I have reviewed this SO post and also this one. From those two I have tried the following suggestions:
I have run nvm alias default v14.17.1 in my root directory
I have pasted the following script into both .zshrc and .bashrc
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Edit: I am on MacOS Big Sur 11.5.2

How to run "nvm" in "oh my zsh"?

In the system there is a nodejs, installed through nvm. The command is not running npm.
Console is Oh my zsh
You can use zsh-nvm or enable it yourself by adding following lines to your ~/.zshrc
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
Extra:
For faster shell initialization, I use lazynvm which only loads node when needed
lazynvm() {
unset -f nvm node npm
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
}
nvm() {
lazynvm
nvm $#
}
node() {
lazynvm
node $#
}
npm() {
lazynvm
npm $#
}
Reference: Lazy load nvm for faster shell start
Switching from Bash to Oh-My-Zsh
If you already have nvm installed and you're switching from bash to oh-my-zsh you can simply open up your .zshrc file and add the nvm plugin that is included with oh-my-zsh:
Open your zsh config file.zshrc in nano with this command: nano ~/.zshrc
Scroll down to where it shows plugins=(git) and add nvm inside the parentheses to make it show as plugins=(git nvm) (separate plugins with spaces)
Press control + O (on macOS), then enter, to save, then press control + X to exit
Then open a new terminal window/tab and enter nvm ls to confirm it works. Note that you must open a new window/tab for your shell to use the newly updated .zshrc config (or enter source ~/.zshrc, etc.)
Source: https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/nvm
This worked for me on Ubuntu 20.04.
Install or update nvm
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Add in your ~/.zshrc
echo 'export NVM_DIR=~/.nvm' >> ~/.zshrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.zshrc
Load in the current shell environment
source ~/.zshrc
Check the nvm version
nvm -v
use homebrew to install nvm
brew install nvm
edit your system configuration
vim ~/.zshrc # or vim ~/.bashrc
export NVM_DIR=~/.nvm
esc > :wq
save file
reload the configuration
source $(brew --prefix nvm)/nvm.sh
view nvm version
$ nvm --version
# 0.36.0
enjoy it.
A much easier solution is to use the nvm plugin that is shipped by default:
It also automatically sources nvm, so you don't need to do it manually
in your .zshrc
git clone https://github.com/nvm-sh/nvm.git ~/.nvm
cd ~/.nvm && git checkout v0.35.1 (current latest release)
Add nvm to your ~/.zshrc. Ex: plugins=(... nvm)
I discovered that there is a nvm plug-in shipping with oh-my-zsh (that's different from lukechilds plugin). After short inspection, I think it adds the necessary modifications to .zshrc when loading, so simply adding nvm to the plugins list in .zshrc should work as well (and it does for me).
I did not find any more details on that default nvm plugin via google so I don't know whether this is the "go-to" solution.
Add this code to .zshrc on your user directory
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
Then run this code on your terminal:
source ~/.zshrc
With Linux (Ubuntu 20.04, 22.04 and 22.10)
With your favorite editor, you edit ~/.zshrc
nano or vi ~/.zshrc
At the end of the file, you add :
# NVM
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
And then you run :
source ~/.zshrc
I strongly suggest using christophemarois' approach to lazy loading nvm (node, npm and global packages) in order to avoid slow shell starting times:
# Add every binary that requires nvm, npm or node to run to an array of node globals
NODE_GLOBALS=(`find ~/.nvm/versions/node -maxdepth 3 -type l -wholename '*/bin/*' | xargs -n1 basename | sort | uniq`)
NODE_GLOBALS+=("node")
NODE_GLOBALS+=("nvm")
# Lazy-loading nvm + npm on node globals call
load_nvm () {
export NVM_DIR=~/.nvm
[ -s "$(brew --prefix nvm)/nvm.sh" ] && . "$(brew --prefix nvm)/nvm.sh"
}
# Making node global trigger the lazy loading
for cmd in "${NODE_GLOBALS[#]}"; do
eval "${cmd}(){ unset -f ${NODE_GLOBALS}; load_nvm; ${cmd} \$# }"
done

Cannot locate pig-core-h1.jar. do 'ant jar', and try again

I have installed pig in my system by using following steps -
first i have downloaded pig-0.14.0.tar.gz
then i have extracted
tar xvzf /home/impadmin/Downloads/pig-0.14.0.tar.gz
sudo mv pig-0.14.0 /usr/local/pig
sudo chown -R hduser:hadoop pig
nano ~/.bashrc
then added the following lines in bashrc file
# PIG binary paths
export PIG_INSTALL="/usr/local/pig"
export PATH="${PATH}:${PIG_INSTALL}/bin"
touch ~/.pigbootup
nano /usr/local/pig/conf/pig.properties
then added the following code in pig.properties
pig.logfile=/home/hduser/hadoop/pig/logs/
after insatllation when i am executing pig version command
then its giving me error -
Cannot locate pig-core-h1.jar. do 'ant jar', and try again
there is a jar file named pig-0.14.0-core-h1.jar so i copied the same file and renamed it as pig-core-h1.jar but still its giving me the same error .
have i done anything wrong during installation?
~/.bashrc should look like this
# PIG binary paths
export PIG_INSTALL="/usr/local/pig"
export PATH="$PATH:$PIG_INSTALL/bin"
No need for the curly brackets
additionally you need to (this or reboot the machine):
$source ~/.bashrc

Bash Unexpected End of File Error After Installing RVM

I executed the following commands under BASH to install RVM:
brew install gnupg gnupg2
gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
\curl -sSL https://get.rvm.io | bash
Now, when I open my terminal, I receive the following error message:
-bash: eval: line 19: syntax error: unexpected end of file
Here is my .bash_profile:
export PATH=/usr/local/bin:$PATH
eval "$(rbenv init -)i"
alias sbl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
#changes prompt to be colorized and rearranges prompt to be "username#hotname:cwd $"
export PS1="\[\033[36m\]\u\[\033[m\]#\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
#enable command line colors, and define colors for the ‘ls’ command
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
#flags -G colorizes output, -h makes sizes human readable, and -F throws a / after a directory
alias ls='ls -GFh'
#Need to add below after 'brew install git bash-completion'
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Can someone point out what is causing the error? I am not familiar with BASH programming. RVM is working.
It looks to me like you have a stray "i" at the end of the second line:
eval "$(rbenv init -)i"
Because of that, eval is trying to run a command sequence that looks something like this:
export PATH="/Users/pc3sq/.rbenv/shims:${PATH}"
# [...]
rbenv() {
# [...]
}i
...and since "}i" is not a valid match for the "{" that starts the function definition, eval runs into the end of the "file" (actually just a string) while it's still looking for a "}" to close the function definition.

Syntax error in rvm bash scripts

My rvm is not working, probably due to an error. When I open new console, it says:
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: syntax error near unexpected token `('
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: ` cd() { __zsh_like_cd cd "$#" ; }'
It's hard to say where the script .rvm/scripts/cd is called. When I remove this line from ~/.bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
there is no error. But when I issue source $HOME/.rvm/scripts/rvm... still there is no error.
My system is Mac OS X 10.9.4
rvm --version:
rvm 1.25.29 (stable) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]
UPDATE
Other scripts in ~/.rvm/scripts:
alias
aliases
autolibs
base
cd
cleanup
cli
completion
cron
db
disk-usage
docs
env
extras
fetch
fix-permissions
functions
gemsets
group
hash
help
hook
info
initialize
install
irbrc
irbrc.rb
list
maglev
manage
migrate
monitor
mount
notes
osx-ssl-certs
override_gem
patches
pkg
prepare
repair
requirements
rtfm
rubygems
rvm
set
snapshot
tools
upgrade
version
wrapper
zsh
My ~/.bash_profile looks like this:
#...not important stuff
source ~/.bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
And in my ~/.bashrc I have this line (and few others):
[ -s "/Users/amorfis/.scm_breeze/scm_breeze.sh" ] && source "/Users/amorfis/.scm_breeze/scm_breeze.sh"
When I remove this line, the error is also gone. And again, it still doesn't show when I run source ~/.scm_breeze/scm_breeze.sh
Scm breeze is installed from here: https://github.com/ndbroadbent/scm_breeze
In source ~/.scm_breeze/scm_breeze.sh there is such piece of code:
if ! type ruby > /dev/null 2>&1; then
echo "Now in if"
# If Ruby is not installed, fall back to the
# slower bash/zsh implementation of 'git_status_shortcuts'
source "$scmbDir/lib/git/fallback/status_shortcuts_shell.sh"
fi
I expected the "if" statement is the problem. So I did this. Added such code before the if:
echo "Now lets try"
if ! type ruby > /dev/null 2>&1; then
echo "trying"
fi
echo "tried"
and inside if, as the first line in the block:
echo "Now in if"
This was the output:
Now lets try
tried
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: syntax error near unexpected token `('
-bash: /Users/amorfis/.rvm/scripts/cd: line 14: ` cd() { __zsh_like_cd cd "$#" ; }'
So it looks like scm_breeze.sh is ok. The problem must be in .rvm, but only when scm_breeze.sh is run.
UPDATE 2:
The beginning of the .rvm/scripts/cd script looks like this:
#!/usr/bin/env bash
# Source a .rvmrc file in a directory after changing to it, if it exists. To
# disable this feature, set rvm_project_rvmrc=0 in /etc/rvmrc or $HOME/.rvmrc
case "${rvm_project_rvmrc:-1}" in
1|cd)
# clonned from git#github.com:mpapis/bash_zsh_support.git
source "$rvm_scripts_path/extras/bash_zsh_support/chpwd/function.sh"
# not using default loadign to support older Zsh
[[ -n "${ZSH_VERSION:-}" ]] &&
__rvm_version_compare "$ZSH_VERSION" -gt 4.3.4 ||
{
cd() { __zsh_like_cd cd "$#" ; }
popd() { __zsh_like_cd popd "$#" ; }
pushd() { __zsh_like_cd pushd "$#" ; }
}
I'd add this in as a comment, but I don't have the reputation to do so. I tried the answer from blob, but it didn't work.
I don't see the "scm_breeze-line", that Riaan Burger was talking about. Has anyone figured out an answer to this?
My error is pretty much the same:
/Users/myusername/.rvm/scripts/cd:14: defining function based on alias `cd' [ruby-2.3.3]
/Users/myusername/.rvm/scripts/cd:14: parse error near `()'
and line #14 says the same:
11 [[ -n "${ZSH_VERSION:-}" ]] &&
12 __rvm_version_compare "$ZSH_VERSION" -gt 4.3.4 ||
13 {
14 cd() { __zsh_like_cd cd "$#" ; }
15 popd() { __zsh_like_cd popd "$#" ; }
16 pushd() { __zsh_like_cd pushd "$#" ; }
17 }
I just ran into the same problem. The solution was to ensure the scm_breeze line executes after all the rvm ones.
Hit the same problem today, but the problem had nothing to do with scm_breeze in my case. If anyone stumbled onto this answer from google or some other place, maybe it'll help you.
Shortly after switching to OSX from Win7 I've been happily modifying anything and everything without necessarily understanding what I'm doing. Amongst other things, I've edited .bashrc as root (not the one from profile, rather the one located in /etc/.bashrc) and aliased cd like that:
alias cd='cd -P'
Never had problems with it before installing RVM, so if you were as root-happy as I once was, it might be worth checking whether you left yourself such a gift in the past.
I've moved said line into ~/.bash_profile and since then RVM happily runs without errors.
So basically what I did,
Step 1) Get a clone from SCM_BREEZE :-
git clone https://github.com/scmbreeze/scm_breeze.git
Step 2) Get a reference from Author's Doc (Link for Docs) and wrote few commands inside my local git repository's terminal,
. "$HOME/.scm_breeze/scm_breeze.sh"
update_scm_breeze
gs
It will update you scm breeze from github and patch your files if any
Your Git Status Command
N you are good to go...
Hope so it would help you now :)