Undoing unsafe PATH changes with sudo - node.js

I needed to install a global npm package (on macos), so I ran the following command:
npm install -g <package-name>
I was given an EACCESS error, and I turned to this Stack Overflow question. I ran the following two commands (from Anirban Sanyal's answer):
sudo chown -R root:$(whoami) /usr/local/lib/node_modules/
sudo chmod -R 775 /usr/local/lib/node_modules/
I once again ran the command npm install -g <package-name>, but it threw an EACCESS error again. I then ran this command:
sudo npm install -g <package-name> --unsafe-perm=true --allow-root
which worked, and my package was installed globally.
I am wondering whether any of these commands have changed something in PATH or root permanently, and if so how I can reverse them.

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

error Cannot find module 'semver' in (npm run dev) command

im using laravel 8 and vuejs to create my website
i have this error after run npm run dev command:
Error: Cannot find module 'semver'
Require stack:
- /usr/share/npm/lib/utils/unsupported.js
- /usr/share/npm/bin/npm-cli.js
...
id tried this solutions:
sudo apt-get purge nodejs --auto-remove
sudo apt-get purge npm --auto-remove
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*
sudo apt-get purge nodejs npm
sudo apt autoremove
npm i -g semver
and then installed again the nodejs and npm (latest version)
but the error still exist
what should i do
There are some modules missing in your /usr/share/npm.
So this will I guess solve the problem
cd /usr/share/npm; npm i
If this doesn't work then you can also just go on installing each missing module in /usr/share/npm.
just try to install npm globally , it will install latest version of npm
sudo npm install -g npm
it worked for me.
The error is basically saying you are missing the module, so you need to install it this way :
npm install semver

How to update NPM 6.13.4 to 7.16.0 on Mac?

I'm studying Laravel, and after I run the command npm run dev, I saw these messages:
New major version of npm available! 6.13.4 → 7.16.0
Changelog: https://github.com/npm/cli/releases/tag/v7.16.0
Run npm install -g npm to update!
But when I run the command: npm install -g npm on terminal, I get a lot of messages about permissions:
The command sudo chown -R 501:20 "/Users/myfolder/.npm" doesn't change anything. I tried to clear the cache with:
npm cache clean --force
Still nothing.
I don't know much about npm and I have this problem on my mac for a long time, since I can't find a way to solve this. I don't even know how to completely remove npm/node. So, I'm pretty stuck.
Can anyone please help me?
npm install -g npm#latest
Install latest version
Permission problem solve
sudo chown -R user:group folder
sudo chmod -R 755 folder
or
sudo npm install -g npm#latest

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

docker elevate user priviledges

I'm trying to sudo for a node install:
sudo npm install -g grunt
sudo npm install -g grunt-cli
sudo npm install -g bower
The commands error stating to run as an administrative user. How do I do that in the Dockerfile?
RUN npm install -g grunt
#RUN ln -s /home/dev/spikes/node-esjs-master/node_modules/grunt /usr/bin/grunt
RUN npm install -g grunt-cli
#RUN ln -s /home/dev/spikes/node-esjs-master/node_modules/grunt-cli /usr/bin/grunt-cli
RUN npm install -g bower
#RUN ln -s /home/dev/spikes/node-esjs-master/node_modules/bower /usr/bin/bower
I don't actually try to sudo in the docker commands...I have after connecting to the container but when prompted for the password I don't know it. I tried to create a sym link but couldn't get that to work. My apologies if this is basic in nature - new environments for me :-).
Thanks!
You don't need to use sudo because all commands in the dockerfile are executed as root. A sample Dockerfile to install those software (Ubuntu Thrusty as base):
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y nodejs npm
RUN npm install -g grunt
RUN npm install -g grunt-cli
RUN npm install -g bower
The same applies for the run command:
$ sudo docker run my_awesome_image whoami
root

Resources