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.
Related
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
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
I am trying to run my app on the Docker. One of the library I am using is https://www.npmjs.com/package/odbc.
In order to install that lib I need to meet the requirements described in the odbc readme:
unixODBC binaries and development libraries for module compilation
on Ubuntu/Debian sudo apt-get install unixodbc unixodbc-dev
on RedHat/CentOS sudo yum install unixODBC unixODBC-devel
odbc drivers for target database
properly configured odbc.ini and odbcinst.ini.
As per Microsoft doc in order to install ODBC Driver 13 for SQL Server https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017#ubuntu-1604-1
I manage to install all the stuff locally on my Mac and successfully connect with the SQL Server on Azure but still have some issues with installing them on the Docker and then run on VSTS.
My Dockerfile:
FROM ubuntu:16.04
USER root
RUN apt-get update
RUN apt-get install --yes curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
RUN apt-get install --yes nodejs
RUN apt-get install --yes build-essential
RUN apt-get install -y npm
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get install -y build-essential
RUN apt-get install -y make
RUN apt-get install apt-transport-https
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev
ADD . /var/www/app
WORKDIR /var/www/app
RUN npm install && \
npm cache clean --force
RUN npm run build
EXPOSE 3000:80
CMD ["npm", "start"]
But so far have an issue with installing NodeJS in line with
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
error: /bin/sh: 1: sudo: not found
I was trying to install only the driver and for installing NodeJs just use some existing Docker images:
FROM ubuntu:16.04
USER root
RUN apt-get update
RUN apt-get install --yes curl
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get install -y build-essential
RUN apt-get install -y make
RUN apt-get install apt-transport-https
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev
FROM node:9-alpine
ADD . /var/www/app
WORKDIR /var/www/app
RUN npm install && \
npm cache clean --force
RUN npm run build
EXPOSE 3000:80
But that approach throws an error:
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:483:19)
gyp ERR! stack at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:397:16)
gyp ERR! stack at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:68:16)
gyp ERR! stack at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/index.js:42:5
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/mode.js:8:5
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:170:21)
gyp ERR! System Linux 4.9.125-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /var/www/app/node_modules/odbc
gyp ERR! node -v v9.11.2
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! odbc#1.4.5 install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the odbc#1.4.5 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/2019-03-08T20_51_17_496Z-debug.log
You are working off the ubuntu:16.04 image, and essentially doing a lot of footwork that the NodeJS guys have already done.
I would go for the image node:10-stretch-slim if I was you. And then install the drivers that you need with apt-get (if available, otherwise script the download and install in your Dockerfile).
The sudo command is not typically installed on docker images, because the user is root by default in the container sessions. If you see any errors concerning sudo, you can generally just remove sudo from the command line that is causing the issue.
Possible solution
Updating my answer here, with a possible solution for you.
This solution will put your application in a node 10 image, based on debian stretch 9. It will get the database drivers for you, from the debian 9 microsoft repository, and install all the packages that I see you are requiring from your question.
I have also added an ENTRYPOINT and CMD in the bottom of the script. But those lines are guesswork, since your question states nothing about how you actually start your application. (If you add that, then I will update my answer).
Note. Notice that I am passing --host 0.0.0.0 to the npm run start command. This is to avoid binding the live server to localhost, which will make in inaccessible from outside the container. Unless you start the container with --network="host".
You may have another means of starting your application that is more "production grade" than the live development server. If so, just replace the lines in the bottom of the Dockerfile, or ask me on this answer.
Dockerfile
# from debian stretch 9.8, node 10
FROM node:10-stretch-slim
# get apt-transport-https, etc., so that we can install by https protocol
RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
build-essential \
make
# add and accept the microsoft signature
RUN curl -q https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
# retrieve the microsoft packagelist for debian 9
RUN curl -q https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
# install the ms odbc sql driver and unixodbc header stuff
RUN apt-get update \
&& ACCEPT_EULA=Y apt-get install -y \
msodbcsql17 \
unixodbc-dev \
&& rm -rf /var/lib/apt/lists
# expose port 80 in containers of this image
EXPOSE 80
# copy working directory into the image and set as pwd
ADD . /var/www/app
WORKDIR /var/www/app
# install dependencies for the application
RUN npm install \
&& npm cache clean --force
# build the application
RUN npm run build
# i am just guessing how you want your app started here, npm?
ENTRYPOINT ["npm"]
# and then this, which makes "npm run start --host 0.0.0.0"
CMD ["run", "start", "--host", "0.0.0.0"]
Build the image with:
docker build -t mynodeapp:0.1 .
Run the application image with:
docker run -p 3000:80 --name mynodeapp mynodeapp:01
Finally visit: http://localhost:3000 to see it working.
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
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.