Permission denied while trying to install opencv4nodejs in Ubuntu - node.js

I was trying to install opencv4nodejs in Ubuntu-20.04 using the following command and my node version is v12.19.0
sudo npm i -g opencv4nodejs
But getting those errors
info install installing opencv version 3.4.6 into directory: /usr/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv
ERR! Error: Command failed: mkdir -p opencv
mkdir: cannot create directory ‘opencv’: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv-build#0.1.9 install: `node ./install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the opencv-build#0.1.9 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-10-28T06_33_21_090Z-debug.log

Running NPM install with sudo might be causing a permissions problem. You could try completely removing the node_modules directory and re-running NPM install it without sudo.
Also make sure you have permission to write to the directory you're installing in?
If it still doesn't work please follow this:
sudo npm install -g opencv4nodejs --unsafe-perm=true --allow-root

This is complete guide to install opencv4nodejs to Linux OS or Raspberry pi (Raspberry Pi OS )
configuration
01- sudo raspi-config expand file system // this is for raspberry pi
After Reboot (sudo reboot now)
02- df -h (To check expand file system)
03- sudo apt-get update && sudo apt-get upgrade -y
04- sudo passwd root // set up your root password
Reboot
To Install NodeJS
01- sudo apt-get install git -y
02- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - // replase 12 with latest nodejs (LTS) version
03- sudo apt-get install nodejs -y
04- sudo apt-get install gcc g++ make
To Install opencv4nodejs
01. sudo apt-get install cmake -y
02. sudo npm install -g node-gyp
I am using this steps for raspberry pi os
03. sudo nano /etc/dphys-swapfile
(Increase the CONF_SWAPSIZE from 100 to 1024)
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
cd to home dir..
04. mkdir opencv
05. cd opencv
06. sudo npm init -y
07. su
// Enter your setup root password
08. sudo npm install --save opencv4nodejs
09. sudo nano /etc/dphys-swapfile
(Set the CONF_SWAPSIZE back to 100)
In index.js and node_modules in same folder
const cv = require("opencv4nodejs");
In index.js and node_modules in not in same folder
const cv = require("path/opencv/node_modules/opencv4nodejs");
! you don't need to install opencv4nodejs for each folders
You can simply call that above way
Hope guys you can understand it...
Any questions feel free to ask...
Thank you

Related

How to set up Truffle and Ganache with Docker on Apple Silicon

error - node-gyp-build: Permission denied while setting up truffle and ganache with docker on Apple Silicon
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v17.9.0/lib/node_modules/truffle/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: 1: node-gyp-build: Permission denied
These are some steps i followed to install truffle with docker on my m1 Macbook.
I'll be doing it for ubuntu image container
docker run -it ubuntu
on your container execute below:
apt-get update && apt-get upgrade
apt-get install sudo build-essential python3 wget curl
Then install nvm from https://github.com/nvm-sh/nvm#install--update-script
On above link there must be these two commands but with updated versions
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
then install node and npm with:
nvm install node
node install npm
npm install npm
after executing
nvm install-latest-npm
you'll find a statement to update npm to the latest version, execute that command, which should look like, npm install -g npm#8.6.0, after that install truffle
npm install -g truffle
there will be a permission issue in executing above command for which you've to execute
sudo chown -R $(whoami) <path to node_modules directory>
Note: the above command has path to node_modules you need to find the path to your node_modules from your error. in my case it was /root/.nvm/versions/node/v17.9.0/lib/node_modules/ so i executed, sudo chown -R $(whoami) /root/.nvm/versions/node/v17.9.0/lib/node_modules/
retry npm install -g truffle
after this you should be done with installation, but you would face problems where you couldn't execute the truffle file.
for this just allow your truffle file to be executed by running:
chmod u+x <path to truffle> you may find the path to truffle with which truffle, execute as below.
chmod u+x /root/.nvm/versions/node/v17.9.0/bin/truffle
For Ganache installation:
npm install ganache --global
To your package.json add,
"scripts": {
"ganache": "ganache --wallet.seed myCustomSeed"
}
Then execute,
npm run ganache
you should be able to see output something like RPC Listening on 127.0.0.1:8545
now execute truffle console, make sure you add correct port number like above 8545 in file truffle-config.js of your code, when you use it.
now execute truffle console

npm install failes with ERR! tar.unpack (raspi)

I try to install Selenium Code Line Runner following this tutorial
https://www.seleniumhq.org/selenium-ide/docs/en/introduction/command-line-runner/
I managed to sudo apt-get install nodejs and sudo apt-get install npm
but I failed with installing selenium-side-runner via sudo npm install -g selenium-side-runner
I get the following error:
npm ERR! tar.unpack ...
See also: error messages
I stumbled upon some tricks as follows:
Installation to SD Card (Raspi)
Card is not full
sudo npm cache clean and retry didn't work
sudo rm -r /usr/local/lib/node_modules/selenium-side-runner and retry didn't work
Any other ideas?
An update of NPM did it!
sudo npm install -g npm#latest

pouchdb-server - Install without sqlite3

I am trying to install pouchdb-server as shown below:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential
sudo npm install -g pouchdb-server
The installation is stuck in an infinite loop with sqlite3. The following message appears repeatedly.
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/pouchdb-server/node_modules/sqlite3/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/lib/node_modules/pouchdb-server/node_modules/sqlite3/.node-gyp/8.11.1"
How do I get rid of these messages for a successful installation?
The following rids the errors mentioned above.
sudo npm install -g pouchdb-server --ignore-scripts

node-red - Installation stuck at gyp for bcrypt

I am running the following commands to install node-red on a AWS EC2 t2.micro instance.
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential
sudo npm install -g node-red
The installation seems to be in an infinite loop at this point:
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/node-red/node_modules/bcrypt/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/lib/node_modules/node-red/node_modules/bcrypt/.node-gyp/8.11.1"
If I hit Ctrl-C and rerun sudo npm install -g node-red then the installation seems to go through successfully. Is this valid behavior?
Try installing with the --unsafe-perm flag.

npm install puppeteer showing permission denied errors

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
sudo apt-get purge nodejs;
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -;
apt-get install -y nodejs;
sudo npm install -g n;
sudo n stable;
Node versions:
$ node -v
v9.4.0
$ npm -v
5.6.0
I try to install:
root#server:/var/www/html# npm install --save puppeteer
Error message:
> puppeteer#1.1.0 install /var/www/html/node_modules/puppeteer
> node install.js
ERROR: Failed to download Chromium r536395! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/var/www/html/node_modules/puppeteer/.local-chromium'
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/var/www/html/node_modules/puppeteer/.local-chromium' }
npm WARN project#1.0.0 No description
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer#1.1.0 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the puppeteer#1.1.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-02-19T15_55_52_669Z-debug.log
I don't see any ways to fix this in the referenced issue: https://github.com/GoogleChrome/puppeteer/issues/375
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!
Run this on your terminal:
sudo npm install -g puppeteer --unsafe-perm=true
Before you begin, make sure you have the most recent version of Node.js.
The Puppeteer Documentation states:
Note: Puppeteer requires at least Node v6.4.0, but the examples below use async/await which is only supported in Node v7.6.0 or greater.
You can check which version of Node.js you have using the following command:
node -v
# OR nodejs -v
If your version of Node.js is less then v7.6.0, you can completely uninstall your current version of Node.js.
Then, you can use complete the reinstallation using a PPA:
sudo apt update
curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
sudo apt install build-essential
You can check the new versions of Node.js and NPM installed on your system:
node -v
npm -v
Finally, you can install Puppeteer:
sudo npm install puppeteer --unsafe-perm=true --allow-root
Now you can run Puppeteer scripts using the node command:
node puppeteer-script.js
I did:
yarn install --ignore-scripts
yarn install.
And it worked without sudo or global package installation.
It should work with npm too.
I have Ubuntu 20.04.

Resources