Install yarn denied - nestjs

I've tried in command "yarn global add #nestjs/cli"
but command return "zsh: command not found: yarn"
so I tried to install yarn "npm install -global yarn"
however, access denied
enter image description here
What should I do?

First check who is the owner of the directory =>
ls -la /usr/local/lib/node_modules/yarn
then change owner to Yourself
sudo chown -R $USER /usr/local/lib/node_modules/yarn
Then try again, you shouldn't have any problems with this error.
npm install --global yarn
you may need to use sudo before npm
sudo npm install --global yarn

Simply do this!
sudo chown -R $USER /usr/local/lib/node_modules
sudo chown -R $USER /usr/local/bin
npm install -g yarn

Related

i can`t use npm install -g serve [duplicate]

What might be causing the error Error: EACCES: permission denied, access '/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! 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! A complete log of this run can be found in:
npm ERR! /Users/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log
Change your file permissions... Like this
First check who owns the directory
ls -la /usr/local/lib/node_modules
it is denying access because the node_module folder is owned by root
drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules
so this needs to be changed by changing root to your user but first run command below to check your current user How do I get the name of the active user via the command line in OS X?
id -un OR whoami
Then change owner
sudo chown -R [owner]:[owner] /usr/local/lib/node_modules
OR
sudo chown -R ownerName: /usr/local/lib/node_modules
OR
sudo chown -R $USER /usr/local/lib/node_modules
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use a hidden directory in your home directory.
Back up your computer.
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 the ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
To test your new configuration, install a package globally without using sudo.
Source: the NPM website.
I tried the solution of the answer given by #okanda but it didn't work for me.
However it worked perfectly when I did it for several folders like mentioned in this thread: https://github.com/angular/angular-cli/issues/9676#issuecomment-464857493
sudo chown -R $USER /usr/local/lib/node_modules/
sudo chown -R $USER /usr/local/bin/
sudo chown -R $USER /usr/local/share/
All you need to do is to add USER to the owner of /local/lib
sudo chown -R $USER /usr/local/lib
EDIT :
To target precisely and only the node_modules folder, try using this command before using the previous one :
sudo chown -R $USER /usr/local/lib/node_modules
try appending sudo before whatever command you are trying.
like this : sudo npm install
Using sudo with a command in Linux/UNIX generally elevates your permissions to superuser levels. In Windows, the superuser account is usually called 'Administrator.' In Linux/Unix the superuser account is generally named 'root'.
The root user has permission to access, modify or delete almost any file on your computer. Normal user accounts can access, modify or delete many fewer files. The restrictions on a normal account protect your computer from unauthorized or harmful programs or users. Some processes require you to perform actions on files or folders you don't normally have permissions to access. Installing a program that everyone can access is one of these actions.
In your case, running the installation command with sudo gives you the permissions of the superuser, and allows you to modify files that your normal user doesn't have permission to modify.
You can install npm through Node version manager or a Node installer. In the docs it states:
We do not recommend using a Node installer, since the Node
installation process installs npm in a directory with local
permissions and can cause permissions errors when you run npm packages
globally.
NPM actually recommends using a Node Version Manager to avoid these errors.
Since you have the permission error, you probably installed npm through a Node installer and now you need to reinstalled it with a nvm (node version manager).
Luckily, this is very simple. You do not even need to remove your current version of npm or Node.js.
All you need to do is
Install nvm.
For OSX or Linux Node use:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/<VERSION>/install.sh | bash
where <VERSION> should be replaced with the latest version
This creates a nvm folder in your home directory.
Then
Install npm and node.js through nvm. To do so, just call
nvm install node
("node" is an alias for the latest version)
Now you can install your package globally without using sudo or changing the owner of node_modules in usr folder.
If you are facing this issue on you Mac. Follow these steps
First checking who is owner of this file by using below command
ls -la /usr/local/lib/node_modules
you will find some file like below one of them is below
drwxr-xr-x 3 root wheel 768 May 29 02:21 node_modules
have you notice that above file is own by root, for make changes inside for you need to change owner ship of path.
you can use check who is current user by this command
id -un (in my case user is yamsol)
and then you can change by calling this command (just replace your user name with ownerName)
sudo chown -R ownerName: /usr/local/lib/node_modules
in my case as you know user is "yamsol" i will call this command in this way
sudo chown -R yamsol: /usr/local/lib/node_modules
thats it.
It looks like you're running into permission issues. If you are installing npm-packages then it might possible that you are getting an EACCES error when trying to install a package globally. This means you do not have permission to write to the directories npm uses to store global packages and commands.
Try running commands: sudo chmod u+x -R 775 ~/.npm and sudo chown $USER -R ~/.npm or you can just run any npm command with sudo, that should get resolve your issue.
If you are installing an npm-package locally, then you should be in your local project directory and can try running sudo npm install <pkg-name> command to install required package. the purpose of using sudo is that it will change your owner permissions so you can make your current user authorized to run npm commands.
I'd recommend you to take a look at https://docs.npmjs.com/getting-started/fixing-npm-permissions
While installing global packages in ubuntu, you need special write permissions as you are writing to the usr/bin folder. It is for security reasons.
So, everytime you install a global package, use:
sudo npm install -g [package-name]
For your specific case, it will be:
sudo npm install -g typescript
Be careful with all responses that change the owner of all directories under /usr/local
Basically, don't mess the Linux system!!!
Using sudo for your local stuff is a really bad recommendation as well.
The original link from www.competa.com is broken, so this is the original approach from there:
npm config set prefix ~/.npm
# open your .bashrc (Linux) or .bash_profile (Mac) file for editing:
nano ~/.bashrc # for Linux
# or...
nano ~/.bash_profile # for Mac if you haven't created a .bashrc file
# add these lines:
export PATH="$PATH:$HOME/npm/bin"
export NODE_PATH="$NODE_PATH:$HOME/npm/lib/node_modules"
# save the file and then enter this command or logout and login to make the changes take effect:
. ~/.bashrc
# or...
. ~/.bash_profile
Option B: Use a version manager like NVM
If it is still not working after giving permissions try running these commands:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
and finally test with this command
npm install -g jshint
This does not work for Windows.
I was trying to install react expo and apart from sudo I had to add --unsafe-perm
like this. This resolves my Issue
sudo npm install -g expo-cli --unsafe-perm
Review this carefully:
https://ionicframework.com/docs/developing/tips#resolving-permission-errors
sudo chown -R $(whoami) /usr/local/{lib/node_modules,bin,share}
sudo chown -R $(whoami) ~/.npm ~/.npmrc
For nvm users
sudo chown -R $USER /home/bereket/.nvm/versions/node/v8.9.1/lib/node_modules
and
sudo chown -R $USER /usr/local/lib/node_modules/
replace v8.9.1 with your node version you are using.
Encountered in CentOS 8 stream
Solution
(1/4) Creating node_modules folder
$ sudo mkdir /usr/local/lib/node_modules
(2/4) Own with Current User
$ sudo chown -R $USER /usr/local/lib/node_modules/
(3/4) Own the bin folder
$ sudo chown -R $USER /usr/local/bin/
(4/4) Own the share folder
$ sudo chown -R $USER /usr/local/share/
Seems like you tried to install a npm package globally rather than locally, as the man npm install describes:
The -g or --global argument will cause npm to install the package globally rather than locally.
Generally, when you are setting up a npm project (among many others that you could have), it's not a good idea to install packages on Node.js global modules (/usr/local/lib/node_modules), as your the debug log suggested.
Instead of using -g, use --save, which will automatically save the package as a dependency for your package.json file:
Like this:
$ npm install express-generator --save
$ cat package.json
{
"name": "first_app_generator",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "ivanleoncz",
"license": "MIT",
"dependencies": {
"express-generator": "^4.16.0"
}
}
But as the other answers mentioned, if you're going to use -g, you have to use sudo (if your user has sudo privileges: see /etc/sudoers) when performing npm install express-generator -g, but indeed, it's not a good idea, possibly causing permission problems.
NOTICE
There are instructions for installing express-generator with -g option, in order to have the script express-cli.js available on the system path, but you can use the locally installed script as well, located at the node_modules if your npm project:
$ ./node_modules/express-generator/bin/express-cli.js --view=pug myapp
If a message like /usr/bin/env: ‘node’: No such file or directory shows up, install nodejs-legacy (Debian/Ubuntu)
IMHO, using -g (also using sudo) is like hic sunt dracones, if you are unsure of the consequences.
For further information:
Creating NPM Package (npm init)
Express.js Generator
I was able to fix the issue using the following in mac.
sudo npm install -g #aws-amplify/cli --unsafe-perm=true
This occurred as a result of npm not being able to access your global node_modules directory locally, running
sudo chown -R Name: /usr/local/lib/node_modules
e.g.
sudo chown -R developerayo: /usr/local/lib/node_modules
fixes the issue, now you can run the command you ran again.
For those of you still unable to fix the problem after using the above mentioned solutions. Try this
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
That should do the trick, cheers!
It is work 100%
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Use this command to install npm as the sudo user:
sudo npm install -g create-react-app
instead of
npm install -g create-react-a pp.
Below command worked for me:
sudo npm install -g appium --unsafe-perm=true --allow-root
Simply you can change the owner or just use sudo before you command like this
sudo chown -R [owner]:[owner] /usr/local/lib/node_modules (change owner)
or
sudo npm install -g json-server
that's it.
For linux / ubuntu if the command
npm install -g <package_name>
npm WARN deprecated superagent#4.1.0: Please note that v5.0.1+ of superagent removes User-Agent header by default, therefore you may need to add it yourself (e.g. GitHub blocks requests without a User-Agent header). This notice will go away with v5.0.2+ once it is released.
npm ERR! path ../lib/node_modules/<package_name>/bin/..
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules
/<package_name>/bin/..' -> '/usr/local/bin/<package_name>'
npm ERR! { [Error: EACCES: permission denied, symlink '../lib/node_modules/<package_name>/bin/..' -> '/usr/local/bin/<package_name>']
npm ERR! cause:
npm ERR! { Error: EACCES: permission denied, symlink '../lib/node_modules/<package_name>/bin/..' -> '/usr/local/bin/<package_name>'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/<package_name>/bin/..',
npm ERR! dest: '/usr/local/bin/ionic' },
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, symlink \'../lib/node_modules/ionic/bin/ionic\' -> \'/usr/local/bin/ionic\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/<package-name>/bin/<package-name>',
npm ERR! dest: '/usr/local/bin/<package-name>' }
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/User/.npm/_logs/2019-07-29T01_20_10_566Z-debug.log
Fix : Install with root permissions
sudo npm install <package_name> -g
You need the permission of superuser levels to install React. In Linux/Unix the superuser account is generally named 'root'.
To get superuser privilege just run the following command on your terminal:
sudo -i
and then simply run the command to install React:
npm install -g create-react-app
However, the reactjs team encourages us to use the following command instead of installing a global package.
npx create-react-app app_name
sudo chown -R $USER /usr/local/lib/node_modules
Similar to POsha's answer but this is what worked for me on ubuntu 19
sudo npm i -g ngrok --unsafe-perm=true --allow-root
From this link
https://github.com/inconshreveable/ngrok/issues/429
Just add "sudo" before npm command. Thats it.
brew uninstall node
brew install node
sudo npm install -g "your_package" --unsafe-perm=true --allow-root
Hopes this helps someone
On my mac similar issue is coming while installing Ionic.
I run the command
sudo chown -R $USER /usr/local/ path you can update as given in error.

I am unable to install nestjs in ubuntu 20.4 [duplicate]

What might be causing the error Error: EACCES: permission denied, access '/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! 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! A complete log of this run can be found in:
npm ERR! /Users/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log
Change your file permissions... Like this
First check who owns the directory
ls -la /usr/local/lib/node_modules
it is denying access because the node_module folder is owned by root
drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules
so this needs to be changed by changing root to your user but first run command below to check your current user How do I get the name of the active user via the command line in OS X?
id -un OR whoami
Then change owner
sudo chown -R [owner]:[owner] /usr/local/lib/node_modules
OR
sudo chown -R ownerName: /usr/local/lib/node_modules
OR
sudo chown -R $USER /usr/local/lib/node_modules
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use a hidden directory in your home directory.
Back up your computer.
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 the ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
To test your new configuration, install a package globally without using sudo.
Source: the NPM website.
I tried the solution of the answer given by #okanda but it didn't work for me.
However it worked perfectly when I did it for several folders like mentioned in this thread: https://github.com/angular/angular-cli/issues/9676#issuecomment-464857493
sudo chown -R $USER /usr/local/lib/node_modules/
sudo chown -R $USER /usr/local/bin/
sudo chown -R $USER /usr/local/share/
All you need to do is to add USER to the owner of /local/lib
sudo chown -R $USER /usr/local/lib
EDIT :
To target precisely and only the node_modules folder, try using this command before using the previous one :
sudo chown -R $USER /usr/local/lib/node_modules
try appending sudo before whatever command you are trying.
like this : sudo npm install
Using sudo with a command in Linux/UNIX generally elevates your permissions to superuser levels. In Windows, the superuser account is usually called 'Administrator.' In Linux/Unix the superuser account is generally named 'root'.
The root user has permission to access, modify or delete almost any file on your computer. Normal user accounts can access, modify or delete many fewer files. The restrictions on a normal account protect your computer from unauthorized or harmful programs or users. Some processes require you to perform actions on files or folders you don't normally have permissions to access. Installing a program that everyone can access is one of these actions.
In your case, running the installation command with sudo gives you the permissions of the superuser, and allows you to modify files that your normal user doesn't have permission to modify.
You can install npm through Node version manager or a Node installer. In the docs it states:
We do not recommend using a Node installer, since the Node
installation process installs npm in a directory with local
permissions and can cause permissions errors when you run npm packages
globally.
NPM actually recommends using a Node Version Manager to avoid these errors.
Since you have the permission error, you probably installed npm through a Node installer and now you need to reinstalled it with a nvm (node version manager).
Luckily, this is very simple. You do not even need to remove your current version of npm or Node.js.
All you need to do is
Install nvm.
For OSX or Linux Node use:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/<VERSION>/install.sh | bash
where <VERSION> should be replaced with the latest version
This creates a nvm folder in your home directory.
Then
Install npm and node.js through nvm. To do so, just call
nvm install node
("node" is an alias for the latest version)
Now you can install your package globally without using sudo or changing the owner of node_modules in usr folder.
If you are facing this issue on you Mac. Follow these steps
First checking who is owner of this file by using below command
ls -la /usr/local/lib/node_modules
you will find some file like below one of them is below
drwxr-xr-x 3 root wheel 768 May 29 02:21 node_modules
have you notice that above file is own by root, for make changes inside for you need to change owner ship of path.
you can use check who is current user by this command
id -un (in my case user is yamsol)
and then you can change by calling this command (just replace your user name with ownerName)
sudo chown -R ownerName: /usr/local/lib/node_modules
in my case as you know user is "yamsol" i will call this command in this way
sudo chown -R yamsol: /usr/local/lib/node_modules
thats it.
It looks like you're running into permission issues. If you are installing npm-packages then it might possible that you are getting an EACCES error when trying to install a package globally. This means you do not have permission to write to the directories npm uses to store global packages and commands.
Try running commands: sudo chmod u+x -R 775 ~/.npm and sudo chown $USER -R ~/.npm or you can just run any npm command with sudo, that should get resolve your issue.
If you are installing an npm-package locally, then you should be in your local project directory and can try running sudo npm install <pkg-name> command to install required package. the purpose of using sudo is that it will change your owner permissions so you can make your current user authorized to run npm commands.
I'd recommend you to take a look at https://docs.npmjs.com/getting-started/fixing-npm-permissions
While installing global packages in ubuntu, you need special write permissions as you are writing to the usr/bin folder. It is for security reasons.
So, everytime you install a global package, use:
sudo npm install -g [package-name]
For your specific case, it will be:
sudo npm install -g typescript
Be careful with all responses that change the owner of all directories under /usr/local
Basically, don't mess the Linux system!!!
Using sudo for your local stuff is a really bad recommendation as well.
The original link from www.competa.com is broken, so this is the original approach from there:
npm config set prefix ~/.npm
# open your .bashrc (Linux) or .bash_profile (Mac) file for editing:
nano ~/.bashrc # for Linux
# or...
nano ~/.bash_profile # for Mac if you haven't created a .bashrc file
# add these lines:
export PATH="$PATH:$HOME/npm/bin"
export NODE_PATH="$NODE_PATH:$HOME/npm/lib/node_modules"
# save the file and then enter this command or logout and login to make the changes take effect:
. ~/.bashrc
# or...
. ~/.bash_profile
Option B: Use a version manager like NVM
If it is still not working after giving permissions try running these commands:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
and finally test with this command
npm install -g jshint
This does not work for Windows.
I was trying to install react expo and apart from sudo I had to add --unsafe-perm
like this. This resolves my Issue
sudo npm install -g expo-cli --unsafe-perm
Review this carefully:
https://ionicframework.com/docs/developing/tips#resolving-permission-errors
sudo chown -R $(whoami) /usr/local/{lib/node_modules,bin,share}
sudo chown -R $(whoami) ~/.npm ~/.npmrc
For nvm users
sudo chown -R $USER /home/bereket/.nvm/versions/node/v8.9.1/lib/node_modules
and
sudo chown -R $USER /usr/local/lib/node_modules/
replace v8.9.1 with your node version you are using.
Encountered in CentOS 8 stream
Solution
(1/4) Creating node_modules folder
$ sudo mkdir /usr/local/lib/node_modules
(2/4) Own with Current User
$ sudo chown -R $USER /usr/local/lib/node_modules/
(3/4) Own the bin folder
$ sudo chown -R $USER /usr/local/bin/
(4/4) Own the share folder
$ sudo chown -R $USER /usr/local/share/
Seems like you tried to install a npm package globally rather than locally, as the man npm install describes:
The -g or --global argument will cause npm to install the package globally rather than locally.
Generally, when you are setting up a npm project (among many others that you could have), it's not a good idea to install packages on Node.js global modules (/usr/local/lib/node_modules), as your the debug log suggested.
Instead of using -g, use --save, which will automatically save the package as a dependency for your package.json file:
Like this:
$ npm install express-generator --save
$ cat package.json
{
"name": "first_app_generator",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "ivanleoncz",
"license": "MIT",
"dependencies": {
"express-generator": "^4.16.0"
}
}
But as the other answers mentioned, if you're going to use -g, you have to use sudo (if your user has sudo privileges: see /etc/sudoers) when performing npm install express-generator -g, but indeed, it's not a good idea, possibly causing permission problems.
NOTICE
There are instructions for installing express-generator with -g option, in order to have the script express-cli.js available on the system path, but you can use the locally installed script as well, located at the node_modules if your npm project:
$ ./node_modules/express-generator/bin/express-cli.js --view=pug myapp
If a message like /usr/bin/env: ‘node’: No such file or directory shows up, install nodejs-legacy (Debian/Ubuntu)
IMHO, using -g (also using sudo) is like hic sunt dracones, if you are unsure of the consequences.
For further information:
Creating NPM Package (npm init)
Express.js Generator
I was able to fix the issue using the following in mac.
sudo npm install -g #aws-amplify/cli --unsafe-perm=true
This occurred as a result of npm not being able to access your global node_modules directory locally, running
sudo chown -R Name: /usr/local/lib/node_modules
e.g.
sudo chown -R developerayo: /usr/local/lib/node_modules
fixes the issue, now you can run the command you ran again.
For those of you still unable to fix the problem after using the above mentioned solutions. Try this
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
That should do the trick, cheers!
It is work 100%
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Use this command to install npm as the sudo user:
sudo npm install -g create-react-app
instead of
npm install -g create-react-a pp.
Below command worked for me:
sudo npm install -g appium --unsafe-perm=true --allow-root
Simply you can change the owner or just use sudo before you command like this
sudo chown -R [owner]:[owner] /usr/local/lib/node_modules (change owner)
or
sudo npm install -g json-server
that's it.
For linux / ubuntu if the command
npm install -g <package_name>
npm WARN deprecated superagent#4.1.0: Please note that v5.0.1+ of superagent removes User-Agent header by default, therefore you may need to add it yourself (e.g. GitHub blocks requests without a User-Agent header). This notice will go away with v5.0.2+ once it is released.
npm ERR! path ../lib/node_modules/<package_name>/bin/..
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules
/<package_name>/bin/..' -> '/usr/local/bin/<package_name>'
npm ERR! { [Error: EACCES: permission denied, symlink '../lib/node_modules/<package_name>/bin/..' -> '/usr/local/bin/<package_name>']
npm ERR! cause:
npm ERR! { Error: EACCES: permission denied, symlink '../lib/node_modules/<package_name>/bin/..' -> '/usr/local/bin/<package_name>'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/<package_name>/bin/..',
npm ERR! dest: '/usr/local/bin/ionic' },
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, symlink \'../lib/node_modules/ionic/bin/ionic\' -> \'/usr/local/bin/ionic\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/<package-name>/bin/<package-name>',
npm ERR! dest: '/usr/local/bin/<package-name>' }
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/User/.npm/_logs/2019-07-29T01_20_10_566Z-debug.log
Fix : Install with root permissions
sudo npm install <package_name> -g
You need the permission of superuser levels to install React. In Linux/Unix the superuser account is generally named 'root'.
To get superuser privilege just run the following command on your terminal:
sudo -i
and then simply run the command to install React:
npm install -g create-react-app
However, the reactjs team encourages us to use the following command instead of installing a global package.
npx create-react-app app_name
sudo chown -R $USER /usr/local/lib/node_modules
Similar to POsha's answer but this is what worked for me on ubuntu 19
sudo npm i -g ngrok --unsafe-perm=true --allow-root
From this link
https://github.com/inconshreveable/ngrok/issues/429
Just add "sudo" before npm command. Thats it.
brew uninstall node
brew install node
sudo npm install -g "your_package" --unsafe-perm=true --allow-root
Hopes this helps someone
On my mac similar issue is coming while installing Ionic.
I run the command
sudo chown -R $USER /usr/local/ path you can update as given in error.

Undoing unsafe PATH changes with sudo

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.

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: EACCES: permission denied, access '/usr/local/lib/node_modules'

What might be causing the error Error: EACCES: permission denied, access '/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! 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! A complete log of this run can be found in:
npm ERR! /Users/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log
Change your file permissions... Like this
First check who owns the directory
ls -la /usr/local/lib/node_modules
it is denying access because the node_module folder is owned by root
drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules
so this needs to be changed by changing root to your user but first run command below to check your current user How do I get the name of the active user via the command line in OS X?
id -un OR whoami
Then change owner
sudo chown -R [owner]:[owner] /usr/local/lib/node_modules
OR
sudo chown -R ownerName: /usr/local/lib/node_modules
OR
sudo chown -R $USER /usr/local/lib/node_modules
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use a hidden directory in your home directory.
Back up your computer.
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 the ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
To test your new configuration, install a package globally without using sudo.
Source: the NPM website.
I tried the solution of the answer given by #okanda but it didn't work for me.
However it worked perfectly when I did it for several folders like mentioned in this thread: https://github.com/angular/angular-cli/issues/9676#issuecomment-464857493
sudo chown -R $USER /usr/local/lib/node_modules/
sudo chown -R $USER /usr/local/bin/
sudo chown -R $USER /usr/local/share/
All you need to do is to add USER to the owner of /local/lib
sudo chown -R $USER /usr/local/lib
EDIT :
To target precisely and only the node_modules folder, try using this command before using the previous one :
sudo chown -R $USER /usr/local/lib/node_modules
try appending sudo before whatever command you are trying.
like this : sudo npm install
Using sudo with a command in Linux/UNIX generally elevates your permissions to superuser levels. In Windows, the superuser account is usually called 'Administrator.' In Linux/Unix the superuser account is generally named 'root'.
The root user has permission to access, modify or delete almost any file on your computer. Normal user accounts can access, modify or delete many fewer files. The restrictions on a normal account protect your computer from unauthorized or harmful programs or users. Some processes require you to perform actions on files or folders you don't normally have permissions to access. Installing a program that everyone can access is one of these actions.
In your case, running the installation command with sudo gives you the permissions of the superuser, and allows you to modify files that your normal user doesn't have permission to modify.
You can install npm through Node version manager or a Node installer. In the docs it states:
We do not recommend using a Node installer, since the Node
installation process installs npm in a directory with local
permissions and can cause permissions errors when you run npm packages
globally.
NPM actually recommends using a Node Version Manager to avoid these errors.
Since you have the permission error, you probably installed npm through a Node installer and now you need to reinstalled it with a nvm (node version manager).
Luckily, this is very simple. You do not even need to remove your current version of npm or Node.js.
All you need to do is
Install nvm.
For OSX or Linux Node use:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/<VERSION>/install.sh | bash
where <VERSION> should be replaced with the latest version
This creates a nvm folder in your home directory.
Then
Install npm and node.js through nvm. To do so, just call
nvm install node
("node" is an alias for the latest version)
Now you can install your package globally without using sudo or changing the owner of node_modules in usr folder.
If you are facing this issue on you Mac. Follow these steps
First checking who is owner of this file by using below command
ls -la /usr/local/lib/node_modules
you will find some file like below one of them is below
drwxr-xr-x 3 root wheel 768 May 29 02:21 node_modules
have you notice that above file is own by root, for make changes inside for you need to change owner ship of path.
you can use check who is current user by this command
id -un (in my case user is yamsol)
and then you can change by calling this command (just replace your user name with ownerName)
sudo chown -R ownerName: /usr/local/lib/node_modules
in my case as you know user is "yamsol" i will call this command in this way
sudo chown -R yamsol: /usr/local/lib/node_modules
thats it.
It looks like you're running into permission issues. If you are installing npm-packages then it might possible that you are getting an EACCES error when trying to install a package globally. This means you do not have permission to write to the directories npm uses to store global packages and commands.
Try running commands: sudo chmod u+x -R 775 ~/.npm and sudo chown $USER -R ~/.npm or you can just run any npm command with sudo, that should get resolve your issue.
If you are installing an npm-package locally, then you should be in your local project directory and can try running sudo npm install <pkg-name> command to install required package. the purpose of using sudo is that it will change your owner permissions so you can make your current user authorized to run npm commands.
I'd recommend you to take a look at https://docs.npmjs.com/getting-started/fixing-npm-permissions
While installing global packages in ubuntu, you need special write permissions as you are writing to the usr/bin folder. It is for security reasons.
So, everytime you install a global package, use:
sudo npm install -g [package-name]
For your specific case, it will be:
sudo npm install -g typescript
Be careful with all responses that change the owner of all directories under /usr/local
Basically, don't mess the Linux system!!!
Using sudo for your local stuff is a really bad recommendation as well.
The original link from www.competa.com is broken, so this is the original approach from there:
npm config set prefix ~/.npm
# open your .bashrc (Linux) or .bash_profile (Mac) file for editing:
nano ~/.bashrc # for Linux
# or...
nano ~/.bash_profile # for Mac if you haven't created a .bashrc file
# add these lines:
export PATH="$PATH:$HOME/npm/bin"
export NODE_PATH="$NODE_PATH:$HOME/npm/lib/node_modules"
# save the file and then enter this command or logout and login to make the changes take effect:
. ~/.bashrc
# or...
. ~/.bash_profile
Option B: Use a version manager like NVM
If it is still not working after giving permissions try running these commands:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
and finally test with this command
npm install -g jshint
This does not work for Windows.
I was trying to install react expo and apart from sudo I had to add --unsafe-perm
like this. This resolves my Issue
sudo npm install -g expo-cli --unsafe-perm
Review this carefully:
https://ionicframework.com/docs/developing/tips#resolving-permission-errors
sudo chown -R $(whoami) /usr/local/{lib/node_modules,bin,share}
sudo chown -R $(whoami) ~/.npm ~/.npmrc
For nvm users
sudo chown -R $USER /home/bereket/.nvm/versions/node/v8.9.1/lib/node_modules
and
sudo chown -R $USER /usr/local/lib/node_modules/
replace v8.9.1 with your node version you are using.
Encountered in CentOS 8 stream
Solution
(1/4) Creating node_modules folder
$ sudo mkdir /usr/local/lib/node_modules
(2/4) Own with Current User
$ sudo chown -R $USER /usr/local/lib/node_modules/
(3/4) Own the bin folder
$ sudo chown -R $USER /usr/local/bin/
(4/4) Own the share folder
$ sudo chown -R $USER /usr/local/share/
Seems like you tried to install a npm package globally rather than locally, as the man npm install describes:
The -g or --global argument will cause npm to install the package globally rather than locally.
Generally, when you are setting up a npm project (among many others that you could have), it's not a good idea to install packages on Node.js global modules (/usr/local/lib/node_modules), as your the debug log suggested.
Instead of using -g, use --save, which will automatically save the package as a dependency for your package.json file:
Like this:
$ npm install express-generator --save
$ cat package.json
{
"name": "first_app_generator",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "ivanleoncz",
"license": "MIT",
"dependencies": {
"express-generator": "^4.16.0"
}
}
But as the other answers mentioned, if you're going to use -g, you have to use sudo (if your user has sudo privileges: see /etc/sudoers) when performing npm install express-generator -g, but indeed, it's not a good idea, possibly causing permission problems.
NOTICE
There are instructions for installing express-generator with -g option, in order to have the script express-cli.js available on the system path, but you can use the locally installed script as well, located at the node_modules if your npm project:
$ ./node_modules/express-generator/bin/express-cli.js --view=pug myapp
If a message like /usr/bin/env: ‘node’: No such file or directory shows up, install nodejs-legacy (Debian/Ubuntu)
IMHO, using -g (also using sudo) is like hic sunt dracones, if you are unsure of the consequences.
For further information:
Creating NPM Package (npm init)
Express.js Generator
I was able to fix the issue using the following in mac.
sudo npm install -g #aws-amplify/cli --unsafe-perm=true
This occurred as a result of npm not being able to access your global node_modules directory locally, running
sudo chown -R Name: /usr/local/lib/node_modules
e.g.
sudo chown -R developerayo: /usr/local/lib/node_modules
fixes the issue, now you can run the command you ran again.
For those of you still unable to fix the problem after using the above mentioned solutions. Try this
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
That should do the trick, cheers!
It is work 100%
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Use this command to install npm as the sudo user:
sudo npm install -g create-react-app
instead of
npm install -g create-react-a pp.
Below command worked for me:
sudo npm install -g appium --unsafe-perm=true --allow-root
On my mac similar issue is coming while installing Ionic.
I run the command
sudo chown -R $USER /usr/local/ path you can update as given in error.
Simply you can change the owner or just use sudo before you command like this
sudo chown -R [owner]:[owner] /usr/local/lib/node_modules (change owner)
or
sudo npm install -g json-server
that's it.
For linux / ubuntu if the command
npm install -g <package_name>
npm WARN deprecated superagent#4.1.0: Please note that v5.0.1+ of superagent removes User-Agent header by default, therefore you may need to add it yourself (e.g. GitHub blocks requests without a User-Agent header). This notice will go away with v5.0.2+ once it is released.
npm ERR! path ../lib/node_modules/<package_name>/bin/..
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules
/<package_name>/bin/..' -> '/usr/local/bin/<package_name>'
npm ERR! { [Error: EACCES: permission denied, symlink '../lib/node_modules/<package_name>/bin/..' -> '/usr/local/bin/<package_name>']
npm ERR! cause:
npm ERR! { Error: EACCES: permission denied, symlink '../lib/node_modules/<package_name>/bin/..' -> '/usr/local/bin/<package_name>'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/<package_name>/bin/..',
npm ERR! dest: '/usr/local/bin/ionic' },
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, symlink \'../lib/node_modules/ionic/bin/ionic\' -> \'/usr/local/bin/ionic\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/<package-name>/bin/<package-name>',
npm ERR! dest: '/usr/local/bin/<package-name>' }
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/User/.npm/_logs/2019-07-29T01_20_10_566Z-debug.log
Fix : Install with root permissions
sudo npm install <package_name> -g
You need the permission of superuser levels to install React. In Linux/Unix the superuser account is generally named 'root'.
To get superuser privilege just run the following command on your terminal:
sudo -i
and then simply run the command to install React:
npm install -g create-react-app
However, the reactjs team encourages us to use the following command instead of installing a global package.
npx create-react-app app_name
sudo chown -R $USER /usr/local/lib/node_modules
Similar to POsha's answer but this is what worked for me on ubuntu 19
sudo npm i -g ngrok --unsafe-perm=true --allow-root
From this link
https://github.com/inconshreveable/ngrok/issues/429
Just add "sudo" before npm command. Thats it.
brew uninstall node
brew install node
sudo npm install -g "your_package" --unsafe-perm=true --allow-root
Hopes this helps someone

Resources