node-reinstall icon indicating copy to clipboard operation
node-reinstall copied to clipboard

Re-Install completed but looks $PATH got disturbed.. node/npm command not found

Open shahzadns opened this issue 9 years ago • 6 comments

Hey Brock..

Thanks for this great tool.. After using it, I am not able to use node/npm/nvm or anything from my terminal.. i tried restart terminal, even reboot the OS. I am using macOS Sierra on my macbook pro device. steps i followed are as following.

1 - cloned the repo and and from terminal cd into the folder. 2 - ran the command bash node-reinstall 6.9.1 3 - provided 1) Yes to all the prompts for re-installing things. 4 - it installed node 6.8.1, after completed, restarted the system and open the Terminal 5 - tried node -v , and got -bash: node: command not found. 6 - nvm, npm, gulp etc.. no command works on Terminal.

Any tip would be much appreciated.

Cheers !

shahzadns avatar Oct 23 '16 00:10 shahzadns

FYI, After trying again bash node-reinstall --nvm, I am getting the follwing results on terminal. (still no node/npm/nvm command works.)

It looks like I need to create a file somewhere.


Shahzads-MacBook-Pro:node-reinstall macbookpro$ bash node-reinstall --nvm
Password:
Installing Node, npm.
=> Downloading nvm from git to '/Users/macbookpro/.nvm'
=> Cloning into '/Users/macbookpro/.nvm'...
remote: Counting objects: 5525, done.
remote: Total 5525 (delta 0), reused 0 (delta 0), pack-reused 5525
Receiving objects: 100% (5525/5525), 1.59 MiB | 301.00 KiB/s, done.
Resolving deltas: 100% (3350/3350), done.
Checking connectivity... done.
* (HEAD detached at v0.25.1)
  master
=> Profile not found. Tried  (as defined in $PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
=> Create it (touch ) and run this script again
   OR
=> Append the following lines to the correct file yourself:
export NVM_DIR="/Users/macbookpro/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
=> Close and reopen your terminal to start using nvm
######################################################################## 100.0%
Checksums empty
Now using node v5.12.0 (npm v3.8.6)
default -> 5 (-> v5.12.0)
node-reinstall is done. 👍
You must restart your terminal for changes to take effect.

shahzadns avatar Oct 23 '16 00:10 shahzadns

After exploring lil more, I got it working by just creating a ~/.bash_profile file at root.

Now the correct steps are as following.

1 - Open Terminal and use cd ~/ (This will take you to the root) 2 - Type touch .bash_profile and hit enter. (This creates a ~/.bash_profile there) 3 - cd to the directory where you have cloned the repo. 4 - Type bash node-reinstall --nvm and hit enter. 5 - Provide the 1 for 1) Yes for all prompts (if any), so the script could re-install stuff. 6 - Restart your Terminal. (no need to restart your system)

Boom ! node, npm, nvm should be working back.

Cheers,

shahzadns avatar Oct 23 '16 01:10 shahzadns

Thanks for providing all of the steps here @shahzadns

I wasn't aware that a user account might not have a dotfile like ~/.profile, ~/.bashrc, or something like ~/.zshrc, so thank you for bringing this to my attention and reporting the bug.

After testing this a little bit, it looks like I could test for the presence of the $PROFILE variable. When I was using ZSH and when I was using Bash, $PROFILE was set to the correct dotfile, so it looks like $PROFILE might be a safe way to determine both the shell in use, and that the dotfile exists. I also tested this by using sudo su with an account that I know doesn't have a login, and it properly reported back with exit code 1 (which means that it was saying the $PROFILE variable wasn't set). It looks like the $PROFILE variable is also what NVM uses.

I'll do a little bit of debugging on this end to make sure that it catches this, but I just wanted to reiterate how much I really appreciate that you reported this bug! When I have a fix, I'll ping you in case you want to test it. Thanks so much!

brock avatar Oct 23 '16 01:10 brock

Hey @brock, Thanks for doing such a great work for the community ! shell is not in my skills set, I wish I could contribute.

P.S Throwing "Profile not found" exception was a nice move.

Good luck !

shahzadns avatar Oct 23 '16 01:10 shahzadns

Hi @brock , I just realized that the modules that were globally installed before using node-reinstall script, are now no longer accessible on Terminal. therefore, I had to re-install them e.g. gulp, bower, etc. Is that expected output ?

Thanks

shahzadns avatar Oct 25 '16 00:10 shahzadns

@brock Still not fixed?

Deilan avatar Aug 21 '17 14:08 Deilan