npm command - sudo or not?

前端 未结 5 789
梦如初夏
梦如初夏 2020-12-01 03:11

Currently I always run sudo npm install but as I understand it\'s not correct.

I want to have opportunity not to use it as root/Adm

5条回答
  •  渐次进展
    2020-12-01 03:31

    In my opinion is the cleanest way to specify the npm prefix:

    npm config set prefix ~/.node_modules
    

    And then to add the following to you .bash_profile

    export PATH=$HOME/.node_modules/bin:$PATH
    

    Now the packages will install into your user directory and no permissions will be harmend.


    EDIT: If you can't install yeoman, create a bash file in one of your PATH directories named yodoctor with the following contents

    #!/bin/bash
    yo doctor
    

    Make the file executable with

    chmod +x yodoctor
    

    And now you should be able to install yeoman.

提交回复
热议问题