npm throws error without sudo

前端 未结 30 1975
清酒与你
清酒与你 2020-11-21 07:43

I just installed node and npm through the package on nodejs.org and whenever I try to search or install something with npm it throws the following error, unless I sudo the c

30条回答
  •  遇见更好的自我
    2020-11-21 08:01

    I had a similar problem at NPM modules won't install globally without sudo, the issue was that when i installed node i did it with sudo via chris/lea ppa repo.

    My solution was to uninstall node and then install it this way:

    Download latest stable node sources from nodejs.org #in my case node-v0.10.20.tar.gz

    tar -zxf node-v0.10.20.tar.gz #uncompress sources

    cd node-v0.10.20 #enter uncompressed folder

    sudo chown $USER -R /usr/local

    ./configure --prefix=/usr/local && make && make install

    PD: If you don't want to change ownership of the /usr/local folder, you can install it somewhere you already own. The problem of this approach is that you will have to bind the installation folder with the bash command line so that we can use the node command later on

    mkdir ~/opt

    ./configure --prefix=~/opt && make && make install

    echo 'export PATH=~/opt/bin:${PATH}' >> ~/.bashrc #or ~/.profile or ~/.bash_profile or ~/.zshenv depending on the current Operative System

    With either of those approaches, you will be able to do the following without using sudo

    npm install -g module_to_install

提交回复
热议问题