Jenkins : npm install fail without sudo - node.js

I need to execute npm install command without sudo but i got this error in my Jenkins job when i tried to execute this command
this is the error console message:
+ npm install
npm WARN grunt-bump#0.8.0 requires a peer of grunt#>=1.0.1 but none
was installed. npm WARN Site_mmm#0.0.1 No repository field. npm WARN
Site_mmm#0.0.1 No license field. npm ERR! Linux 3.13.0-32-generic npm
ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" npm
ERR! node v5.1.0 npm ERR! npm v4.0.2 npm ERR! path
/var/lib/jenkins/workspace/mmm/node_modules/.staging npm ERR! code
EACCES npm ERR! errno -13 npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir
'/var/lib/jenkins/workspace/Site_SiFAST_-_Intégration_Continue/node_modules/.staging'
npm ERR! at Error (native) npm ERR! { [Error: EACCES: permission
denied, mkdir
'/var/lib/jenkins/workspace/Site_SiFAST_-_Intégration_Continue/node_modules/.staging']
npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall:
'mkdir', npm ERR! path:
'/var/lib/jenkins/workspace/Site_SiFAST_-_Intégration_Continue/node_modules/.staging'
} npm ERR! npm ERR! Please try running this command again as
root/Administrator.
Anyone khow how to execute this command without sudo?

I think you need to change to access of the directory for which you are getting error by using chmod command .change it in such a way that Jenkins user is able to create directory

thanks #pushpendra chouchan :
Fixed by :
sudo chown -R [jenkins-user] /user/local/lib/node_modules/
sudo chown -R [jenkins-user] /user/local/bin/
sudo chown -R [jenkins-user] /user/local/lib/share/

the answer is to find here:
Run shell command in jenkins as root user?
jenkins user is per default not a sudoer(https://wiki.archlinux.org/index.php/sudo#Using_visudo).
So its not possible to add sudo before a command.
you can try to add jenkins to sudoers but this wasnt working for me.
i did it that way from the link i added.
make changes in jenkins config file /etc/default/jenkins (for most of the linux distributions) or /etc/sysconfig/jenkins (for redhat/centOS distribution)

Related

I an facing this issue while installing the package cowsay globally. How do I fix it?

I had tried to install cowsay package globally with the help of npm, but I'm facing the following error.
npm i -g cowsay
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/cowsay
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/cowsay'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/cowsay'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/cowsay'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
To get the list of directories and their owners:
ls -l
Find the folder that npm is installing to, change ownership permissions to your user. You can do that by:
sudo chown <user_id> <folder_name>
This will change the owner permissions of the given folder to your user. Now npm should install just fine.
Paste the following command and run it:
sudo chown -R $USER /usr/local/lib/node_modules/
After that run the original command:
npm i -g cowsay

Expo CLI issue on ubuntu

I have downloaded expo cli on ubuntu 20.04 in my root directory but I am unable to download it globally!
I want expo cli to be there globally since it's not recommended to open code editor through root directory.
This is what my terminal shows!
npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/yarn/bin/yarn.js
npm ERR! dest /usr/local/bin/yarn
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/local/bin/yarn'
npm ERR! { [Error: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/local/bin/yarn']
npm ERR! cause:
npm ERR! { Error: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/local/bin/yarn'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/yarn/bin/yarn.js',
npm ERR! dest: '/usr/local/bin/yarn' },
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, symlink \'../lib/node_modules/yarn/bin/yarn.js\' -> \'/usr/local/bin/yarn\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/yarn/bin/yarn.js',
npm ERR! dest: '/usr/local/bin/yarn' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ritik/.npm/_logs/2020-07-03T19_44_34_737Z-debug.log
This is a permissions issue. you can use sudo to fix this but as a general recommendation never run npm install with sudo because it is a bad idea in general ,you can read more about this here
So To minimize this issue you can configure npm to use a different directory for global packages installations as mentioned in npm docs here
On the command line, In your home directory, create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
Finnaly try to install expo-cli globally :
npm install -g expo-cli
Or if you want a quick fix you can try this
open a terminal and run :
sudo chown -R $USER:$USER /usr/local/lib/node_modules
try to install expo-cli , run :
npm i -g expo-cli
Also consider to avoid globall installs and use npx when possible read more here

Error: EACCES: permission denied, mkdir when installing sth with npm

Everytime I try to install something with npm (in this case electron-packager) I run into this error. How can I solve this issue?
I have already tried to give me access by changing the permissions on .npm via chmod, but it didn't work and I also tried it with another node version (installed via nvm: node -v 12.1.0; npm -v 6.9.0) and it didn`t work as well.
$ npm install electron-packager --save-dev
npm ERR! path /Users/felixmoser/.npm/_cacache/index-v5/15/a0
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'
npm ERR! [OperationalError: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'] {
npm ERR! cause: [Error: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'
npm ERR! },
npm ERR! isOperational: true,
npm ERR! stack: 'Error: EACCES: permission denied, mkdir ' +
npm ERR! "'/Users/felixmoser/.npm/_cacache/index-v5/15/a0'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/Users/felixmoser/.npm/_cacache/index-v5/15/a0',
npm ERR! parent: 'electron-packager'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/felixmoser/.npm/_logs/2019-05-01T14_11_08_530Z-debug.log
I actually don't know what else I should try now and hope, that you guys can help me solve this problem!
change the ownership of .npm folder,
In my case I couldn't figure out the solution so I used
sudo chown -R $(whoami) ~/.npm
Just change the owner of ~/.npm folder to yourself:
sudo chown -R felixmoser ~/.npm
You'll need to enter your password for calling sudo.
There is also a similar problem with permissions when trying to install packages globally with --global or -g. I know it's not your current problem, but I want to add it here because people googling the EACCESS when doing a global install might reach this question as well.
Some people change the system folder privileges allowing non-root users writing in system folder, however here is what they recommend in the documentation:
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally/
Back up your computer (including it here because documentation mentions is too, but it feels to me overly cautious)
Then execute:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Edit your ~/.profile:
export PATH=~/.npm-global/bin:$PATH
Then invoke it with
source ~/.profile
To test your new configuration, install a package globally without using sudo:
npm install -g jshint
Or instead of modifying ~/.profile just use the corresponding ENV variable (but to make it pernament you would have to modify the profile file anyway)
NPM_CONFIG_PREFIX=~/.npm-global
Simply add sudo
So instead of npm install electron-packager --save-dev
Let it be sudo npm install electron-packager --save-dev
Please consider running the instructions at least inside the user's location, for example:
/home/myuser/
express HelloWorld --view=pug

error while installing "npm install -g ionic cordova"

When I install npm install -g ionic cordova It throws below error
npm WARN checkPermissions Missing write access to
/usr/lib/node_modules npm ERR! path /usr/lib/node_modules npm ERR!
code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error:
EACCES: permission denied, access '/usr/lib/node_modules' npm ERR! {
Error: EACCES: permission denied, access '/usr/lib/node_modules' npm
ERR! stack: 'Error: EACCES: permission denied, access
\'/usr/lib/node_modules\'', npm ERR! errno: -13, npm ERR! code:
'EACCES', npm ERR! syscall: 'access', npm ERR! path:
'/usr/lib/node_modules' } npm ERR! npm ERR! The operation was
rejected by your operating system. npm ERR! It is likely you do not
have the permissions to access this file as the current user npm ERR!
npm ERR! If you believe this might be a permissions issue, please
double-check the npm ERR! permissions of the file and its containing
directories, or try running npm ERR! the command again as
root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in: npm ERR!
/home/javauser/.npm/_logs/2018-05-19T04_42_24_737Z-debug.log
I tried with root user as well.
I am using node v9.11.1 , npm 6.0.1
Never use npm with sudo (or as root)! You can create potential backdoor to your system.
I have just answered a very similar question in the following link: How to fix the problem with vue.js instalation
Basicaly what is happening is that NPM does not have the privileges to access /usr/local/lib. To give it access, you could change the ownership of ~/.npm in order to belong to your current user. This could be this way:
sudo chown -R $(whoami) ~/.npm
This way you do not have to run npm as sudo, which is not recomended. I believe that it is due to vulnerabilities that are known in npm packages.
Here is an article about it: Don't use "sudo" with npm "install"
run with sudo in Mac OS or linux
sudo npm install -g ionic cordova
or in windows open cmd with run as administrator
npm install -g ionic cordova

node.js install errors on mac

Hello i need install node.js via terminal. After install to system the installator wrote me:
Make sure that /usr/local/bin is your $PATH.
After running
echo "$PATH"
It returned
/usr/local/git/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/bin:/usr/local/git/bin:/usr/local/lib
But when i want install by npm install -g less
It shows me:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
/usr/local/lib
npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "less"
npm ERR! node v6.3.1
npm ERR! npm v3.10.3
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/erikmargony/npm-debug.log
What can i do to install it? I feel realy lost.
You need to install as the super user. To do this you write sudo at the begining of the command.
sudo npm install -g less
You will then be asked for your user password.
You can find more information here: npm throws error without sudo
In particular you can change the ownership back to your user login using the following command, taken from the aforementioned answer.
This looks like a permissions issue in your home directory. To reclaim ownership of the .npm directory execute:
sudo chown -R $(whoami) ~/.npm
I would suggest you take the time to understand something about permissions in your operating system, and in particular be careful when using the sudo command. Things can go wrong very quickly when logged in as the super user.

Resources