node.js install errors on mac - node.js

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.

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

npm install -g failing, getting npm ERR! code EACCES

When I run npm install -g typescript the following message shows:
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/typescript
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/typescript'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/typescript'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/typescript'
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.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/alexz/.npm/_logs/2021-12-26T10_45_08_412Z-debug.log
I tried to check if I have successfully installed TypeScript, if I run npm ls typescript it shows:
alexz# /Users/alexz
└── typescript#4.5.4
I am confused if I have installed TypeScript or not, because if I do tsc -v it tells me the tsc command is not found. How do I fix the above problem? Thanks!
It is a permission issue. You could read Resolving EACCES permissions errors when installing packages globally to change npm's permissions or you could use sudo command as below.
It may ask you your computer password.
sudo npm install -g typescript

Gulp installation permission issue

I want to install Gulp 4.0.2 on Mac but it fails due to missing write access.
$ npm i -S gulp -g
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
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! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/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).
Seems Gulp installation requires root privileges but it is not recommended. I don't want to install gulp as administrator :(
Is it possible to create another user w/o root privileges and install Gulp from there? If yes, how to do that?
Any advice will be appreciated, thanks!
You can install gulp local to your project directory rather than globally:
npm install gulp
You can then run the local version using npx:
npx gulp
Note: npx comes bundled with NPM version 5.2+
You could also use a script in your package.json:
"scripts": {
"gulp": "gulp"
}
npm run gulp
Official docs to avoid these permission issues...
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
Be sure to try touch ~/.zshrc if you're on a newer mac.

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

Jenkins : npm install fail without sudo

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)

Resources