-
Star
(237)
You must be signed in to star a gist -
Fork
(49)
You must be signed in to fork a gist
-
-
Save brock/5b1b70590e1171c4ab54 to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # nodereinstall | |
| # credit: http://stackoverflow.com/a/11178106/2083544 | |
| # get list of global npm modules to reinstall | |
| # omit the lib directory listing | |
| GLOBAL_MODULES=`npm -g list --depth 0 --parseable | xargs basename | sed -E 's/^(lib|npm)$//g'` | |
| # NVM will think it is still installed if NVM_DIR is still set | |
| unset NVM_DIR | |
| # erase all possible install paths | |
| rm -rf /usr/local/lib/node* | |
| rm -rf /usr/local/include/node* | |
| rm -rf ~/{local,lib,include,node*,npm,.npm*} | |
| rm -rf /usr/local/bin/{node*,npm} | |
| rm -rf /usr/local/bin/npm | |
| rm -rf /usr/local/share/man/man1/node.1 | |
| rm -rf /usr/local/lib/dtrace/node.d | |
| rm -rf ~/.npm | |
| rm -rf ~/.nvm | |
| # go home and install NVM just because I feel safe there | |
| cd $HOME | |
| # curl https://raw.githubusercontent.com/creationix/nvm/v0.16.0/install.sh | bash | |
| # get the latest version - the gist I'm curling calls the above curl command | |
| curl https://gist.githubusercontent.com/brock/e0b10c2d9624dae694db/raw/157b067b0820967666a3d2c9b7961560bc98970f/latest.sh | bash | |
| # you must "source" the NVM exports - yours are most likely in ~/.zshrc or ~/.bashrc or ~/.bash_profile | |
| source ~/.zshrc | |
| # source ~/.bashrc | |
| # source ~/.bash_profile | |
| # install the latest 0.10 version of node then set it as the default | |
| nvm install 0.10 | |
| nvm alias default 0.10 | |
| echo "Reinstalling your global npm modules:" | |
| echo $GLOBAL_MODULES | |
| npm install --global $GLOBAL_MODULES |
Thank you very much for this. I changed nvm install to stable :)
Thanks a lot!! This saved my whole day. You deserve a Medal Of Honour for this!
🍺
Thank you! This is a lifesaver. I changed the NODE_VERSION to 5.10
Thank you so much. I was in a downward spiral of installing/uninstalling and your script pulled me out!
Thank you. It really helped a lot. Very good idea.
Awesome. upgraded to 7.0 with this and everything appears to be working fine.
You sir are the bomb! thank you for saving me from so much pain :)
🍺
Amazing! Thanks so much!
Sir, you deserve a diamond medal of honour. Thanks forever!
I wish I could buy you a Beer. Thanks a lot.
It didn't work for me. Not sure what went wrong honestly, but following this manual instructions worked: https://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x
You save my mind! Thanks
Thank you, amazing!
This script is awesome!
Could you please update it to most up-to-date node version? or maybe with a line asking for desired version?
Thanks!
@Moondancer83 See the repo for some of those updates: https://github.com/brock/node-reinstall
This script definitely is battle-tested!
Thanks! It saved my day.
PS: I use Linux Mint Tessa.
This didn't install it for macOS zsh (which is default now)
This is awesome. I had almost given up. Thanks!
gif had meh lolz
Incredible work. Thank you!
You're a legend. I ran into an issue with AWS SAM, and this was the solution that fixed it.
@david-rodriguez I've not updated this in a long time, so it is still using a default Node.js version from 2014. Be sure to install a newer version of node before you get started! Something like nvm install 16
@brock I tweaked the script before running it to install the latest version of node. Nonetheless, you did most of the heavy lifting.
Working perfectly on 1 Aug'23. Thanks a ton.
Two small suggestions:
/usr/local/share/doc/nodeand/usrl/local/share/systemtap/tapset/node.stpare not cleaned up.- update installation steps as shown on nvm-sh/nvm
@seguri Thanks for posting the feedback on this script.
Can you share more info on what installer uses each of these install paths? I don't like adding directory deletions without vetting them to some degree in case someone blindly runs my scripts.
/usr/local/share/doc/node/usr/local/share/systemtap/tapset/node.stp
And what needs to be updated to the installation steps from nvm-sh/nvm? I'm not up to date on their changes since they move a lot more than I do.
I don't typically update this Gist, but I do make updates to the node-reinstall repo when major changes need to happen, and would be happy to bring it up to date if it makes sense.
Replying here is fine, but if you're familiar with git and Github and want to create a Pull Request with the proposed changes, I'd happily review it and add you to the contributors.
Beautiful.