npm install puppeteer showing permission denied errors
Run this on your terminal:
sudo npm install -g puppeteer --unsafe-perm=true
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!