How to set up Truffle and Ganache with Docker on Apple Silicon - node.js

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

Related

npm install global in Dockerfile

Trying to install resume-cli through docker but getting some permission errors on installing resume-cli.
Dockerfile:
FROM python:3.7-slim-buster
RUN apt-get update
RUN apt-get install -y curl
SHELL ["/bin/bash", "--login", "-c"]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
RUN nvm install 15.13.0
RUN npm install -g resume-cli --unsafe-perm=true --allow-root
RUN npm install -g jsonresume-theme-paper
and i run: docker build -t containernpm .
where I get Error on RUN npm install -g resume-cli --unsafe-perm=true --allow-root:
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v15.13.0/lib/node_modules/resume-cli/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.js
npm ERR! sh: 1: node: Permission denied
btw next line RUN npm install -g jsonresume-theme-paper (with -g) runs normally without permission error.
Any idea how to overpass that without removing -g on RUN npm install -g resume-cli --unsafe-perm=true --allow-root
? (by removing -g runs without error)
I can't say I know why the permissions errors are happening, but here is a Dockerfile that works.
FROM node:15.13.0-buster-slim
RUN npm install -g resume-cli
ENTRYPOINT ["resume"]
There is a related question (sh: 1: node: Permission denied) but the top-voted answer there does not work for me.

Permission denied while trying to install opencv4nodejs in Ubuntu

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

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.

npm install: Error: EACCES: permission denied, mkdir

I attempted to do a sudo npm install -g appium on Mac OS 10.12.5.
I get this error:
info Chromedriver Install Installing Chromedriver version '2.30' for platform 'mac' and architecture '64'
info Chromedriver Install Opening temp file to write chromedriver_mac64 to...
Error: EACCES: permission denied, mkdir
'/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/2017820-44752-12jfqpb.z2hd'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! appium-chromedriver#3.0.1 install: node install-npm.js
npm ERR! Exit status 1
npm ERR!
this is not a dup question, as this install attempt was with sudo, as the other one was not.
sudo npm install -g appium --unsafe-perm=true --allow-root
Worked for me
you are using npm so you have to use
sudo npm install --unsafe-perm
In unsafe mode with every command you run
hopefully, it will help
The -g option means install globally. When packages are installed globally, EACCES permission errors can occur.
Consider setting up npm to operate globally without elevated permissions. See Resolving Permission Errors for more information.
Option 1
The best way to avoid permission issues is to reinstall NodeJS and npm using a node version manager.
1. Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
You can close and reopen the terminal ou just open another terminal and check if nvm is installed properly with this command: command -v nvm.
2. To download and install the latest LTS release of NodeJS, run:
nvm install --lts
3. Set the newly installed NodeJS as the default environment:
nvm alias default lts/*
Option 2 (Does not apply for windows)
Change the owner of npm's directories to the current user:
sudo chown -R $(your_user) /usr/local/{lib/node_modules,bin,share}
sudo chown -R $(your_user) ~/.npm ~/.npmrc
I reinstalled Node/NPM. Problem solved.

sudo npm install command not found

I have installed nodejs and npm in my server (os:amazon ami) using node version manager
current node version is 7.10.0
npm version is 4.2.0
nodejs project is located in var/www/testing folder when i am trying to install the depeondeies present in package.json using sudo npm install i got command not found error
Path of node and npm is respectively
~/.nvm/versions/node/v7.10.0/bin/node
~/.nvm/versions/node/v7.10.0/bin/npm
npm and node are in same folder but when I try this command:
sudo npm install I got sudo: npm: command not found
npm install command throws no errors but node_modules folder is empty.
Correct npm path is /usr/local/bin/npm else just run below command again
sudo apt-get install npm
And verify the npm is install, Alternatively you can try:
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
I got this error when I tried to install npm.
bash-3.2$ sudo npm install
sudo: npm: command not found
So, I downloaded node.js from https://nodejs.org/en/
It will automatically set at the required path.
After installation, it worked for me.
Try To Install Node Using Nvm Node Version Manager
From Officai NVM Git Hub Repo
https://github.com/nvm-sh/nvm
git clone https://github.com/nvm-sh/nvm
cd nvm
./installer.sh
nvm install <AnyNodeVersion>
Now Hit Command Line
This Method Actually Worked For ME
i Face same Issue And Explained It Here
https://stackoverflow.com/questions/67285266/npmcommand-not-found-node-v-is-working-but-for-npm-command-not-found

Resources