0

I'm pretty new to bash scripting and I'm trying to write a simple script that installs NVM and NODE. This is what I've got:

#!/bin/bash

echo "==> Installing node version manager (NVM)."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
. ~/.nvm/nvm.sh
echo "==> Installing NodeJS"
nvm install node
echo "==> Install complete"

When I run the script it all looks like it works, and I have an .nvm folder in the directory afterwards, but the commands nvm and node don't work, I just get -bash: node: command not found. I'm assuming this is a linking issue, but I don't know what to add to the script to fix it.

##Edit It does get added to my .bashrc like 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

Any help appreciated.

Mr.P
  • 1,390
  • 13
  • 35
  • Because whereever it puts the binary, that path is not added to your system $PATH variable. https://opensource.com/article/17/6/set-path-linux – The Fool May 21 '21 at 07:35
  • Nope. It's added to my `.bashrc` – Mr.P May 21 '21 at 07:44
  • I think you need to add that nested path too. Currently, it won't find the binary if it's placed like shown here. https://stackoverflow.com/questions/34770719/where-does-nvm-store-node-js-installations/34770755 – The Fool May 21 '21 at 07:46
  • @TheFool that's the issue alright!! But I can't add that to the script cause it will run in it's own shell instance. What's the solution for that? – Mr.P May 21 '21 at 07:49
  • 1
    Ahhhh I got it. Running it as source will do it. So instead of calling `./node_installer.sh` I just run `. ./node_installer.sh` – Mr.P May 21 '21 at 07:52

0 Answers0