8

I started using fish as my shell yesterday, and today I tried to run my NextJs App in the terminal using yarn and tailwind gave me an error about the node version. I checked it, and then I noticed that the current version was 10.19.0.

In my zsh shell, I have node, npm and nvm installed, and I can use them without any errors, but in my fish shell, only node is present. I tried to install nvm in the terminal with this command:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash 

and the following output was:

=> nvm is already installed in /home/gabriel/.nvm, trying to update using git
=> error: pathspec 'v0.31.4' did not match any file(s) known to git

=> Source string already in /home/gabriel/.profile
main: linha 293: /nvm.sh: Arquivo ou diretório não encontrado
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="/home/gabriel/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm⏎ 

The last instruction gives me commands I can use to run nvm, but when I run them, I get an error

Commands given

export NVM_DIR="/home/gabriel/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

Output

~/.nvm/nvm.sh (line 942): Unexpected ')' found, expecting '}'
      "${NVM_NODE_PREFIX}")
                          ^
from sourcing file ~/.nvm/nvm.sh
        called on line 185 of file /usr/share/fish/config.fish
in function '.' with arguments '/home/gabriel/.nvm/nvm.sh'
source: Error while reading file “/home/gabriel/.nvm/nvm.sh”

gabriel_tiso
  • 1,007
  • 3
  • 11
  • 27
  • fish is not POSIX compliant.. Which means nvm cannot support it.. [check out this tutorial](https://eshlox.net/2019/01/27/how-to-use-nvm-with-fish-shell) to circumvent and run nvm – Subham Burnwal Apr 14 '21 at 20:47

1 Answers1

8

So, I found two ways,

One is using nvm with only bash. Whenever you need to use nvm command, use bash. Then go back to fish and do all the node relates stuffs, change nvm use [version] in bash. Then work in fish and still it will use the version NVM sets.

Another is, install curl, install fisher, install bass plugin to support bash style in fish,

sudo apt install curl

curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher

fisher install edc/bass

Create nvm.fish sudo nano ~/.config/fish/functions/nvm.fish

Add this code to the file nvm.fish

function nvm
    bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end

Now, you can use nvm command in Fish

  • Based on your answer, I changed `nvm.fish` to `bash -c "source ~/.bash_nvm && nvm $argv && fish"` while `.bash_nvm` contains the nvm setup for bash. Might have other downsides I am not aware of, but does not require any additional dependencies. – Florian Link Feb 09 '22 at 09:49
  • the bass method worked! – callback Aug 15 '22 at 09:36