npm install puppeteer showing permission denied errors

前端 未结 3 1281
北荒
北荒 2021-01-05 17:55

I\'m unable to install puppeteer as a project dependency, and I\'ve tried re-installing node. Anyone have an idea on how to fix this? Running Ubuntu 17.10 x64

3条回答
  •  庸人自扰
    2021-01-05 18:27

    EDIT 20th April 2019:

    The easy solution suggested by lauraalvarezz1 is,

    sudo npm install -g puppeteer --unsafe-perm=true
    

    This is okay as long as you trust puppeteer and want it to install puppeteer globally.

    However beware of using --unsafe-perm=true for permission related problems. Reasons are:

    • Running unsafe-perm=true with sudo, as a non-root user, will give the script root access. This might be okay only if you trust the script and do not concern about security that much.
    • You might need to use --no-sandbox in every script you run, because the chrome installed with this command might not run without this parameter. See this github issue.

    You have installed npm with sudo. Thus anything you install globally will require sudo.

    To install anything on var/www/html folder, either you have to own that folder,

    sudo chown -R $USER /var/www/html
    

    Or you can use nvm to manage npm. Technically it will use your home directory and your current user.

    After installing nvm, you can install puppeteer globally with it,

    npm i -g puppeteer
    

    or you have to use sudo

    sudo npm install --save puppeteer
    

    However chromium will not be downloaded due to permission error, that's why you have to use ---unsafe-perm=true as stated before.

    Security Related Resources:

    • Resolve this without sudo, you can use this answer.
    • Learn more about best practices dealing with /var/www folder, refer to this answer.

    Best of luck!

提交回复
热议问题