How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

前端 未结 28 2195
难免孤独
难免孤独 2020-11-21 05:28

My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19.

My node version is:



        
28条回答
  •  死守一世寂寞
    2020-11-21 06:23

    This fixed it for me Fixing npm On Mac OS X for Homebrew Users. And it does not require too many steps.

    Just go to the solution part if you don't care about the why.

    Here is the relevant part for convenience:

    Solution

    This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

    Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

    Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the correct defaults, configure the location for global npm modules to be installed, and then install npm as its own pacakge.

    rm -rf /usr/local/lib/node_modules
    brew uninstall node
    brew install node --without-npm
    echo prefix=~/.npm-packages >> ~/.npmrc
    curl -L https://www.npmjs.com/install.sh | sh
    

    Node and npm should be correctly installed at this point. The final step is to add ~/.npm-packages/bin to your PATH so npm and global npm packages are usable. To do this, add the following line to your ~/.bash_profile:

    export PATH="$HOME/.npm-packages/bin:$PATH"
    

    Now you can re-install any global npm packages you need without any problems.

提交回复
热议问题