How to use the brew version of a command (aws-es-proxy) instead of node? - npm

I used npm -i -g aws-es-proxy. But I actually wanted to do brew install aws-es-proxy because the commands are slightly different for these two packages depending on whether installed with npm or brew. So I did npm uninstall -g aws-es-proxy and after uninstalling and deleting the folder that was still left over
$ cd /Users/USER_NAME/.nvm/versions/node/v10.17.0/bin/
$ ls
aws-azure-login node npm npx
bin USER_NAME$ rm -r aws-azure-login
I still would get
$ aws-es-proxy -listen :9200 -ENDPOINT
-bash: /Users/USER_NAME/.nvm/versions/node/v10.17.0/bin/aws-es-proxy: No such file or directory
It seems like this terminal is using npm version instead of brew version. Can you let me know how I can force to use the brew installation for this command?

Actually, all I had to do was open a new terminal session and it recognized the command. Not sure what behind the scenes stuff was happening.

Related

What npm install -s mean?

I am installing some packages on NPM, sometimes I have to write -s and -g? What do they mean?
npm install -s socket.io
npm install -g xxxxxxx
npm -g <package> will install a package globally on your machine. Without the -g or --global flag, the package will be installed locally in the directory you were in when you ran the command.
npm -S <package> with an uppercase -S or --save will install the package and save it to your dependencies in your package.json, although I believe that is now the default behavior in current npm. I recommend reading the docs if you're unfamiliar with what's happening when you pass different options to npm.
#gmmetheny answered the question about the global -g flag, but -s appears to silence the output of the command (at least in npm v7.0.15).
In other words, including -s (or --silent) in your npm install command means that it will have no output (only a newline):
> npm install -s example-package1 example-package2
This may be useful for running the command in a script.
Running the command without the -s flag echoes information about what was installed, e.g.:
> npm install example-package1 example-package2
npm WARN deprecated some-pkg#1.2.3: this library is no longer supported
added 160 packages, and audited 160 packages in 6s
14 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
You can diff the resulting directories created after running each variant of the command and you can verify that the effects are the same.
As #Max mentioned, this option is NOT mentioned in the npm docs (at least not in any prevalent location where a user might find it after a reasonable amount of searching).

Error: node_modules directory is missing. Please run `npm install` in your project directory

expo start
[21:03:34] Starting project at /home/sadaif/Documents/React-Native-App/my
[21:03:35] Expo DevTools is running at http://localhost:19002
[21:03:35] Opening DevTools in the browser... (press shift-d to disable)
[21:03:41] Error: node_modules directory is missing. Please run `npm install` in your project directory.
[21:03:41] Couldn't start project. Please fix the errors and restart the project.
[21:03:41] Set EXPO_DEBUG=true in your env to view the stack trace.
I run this command npm install but noting happened
then i run these commands
rm -rf node_modules
rm package-lock.json
npm cache clear --force
npm install
When I run command expo start then this error show in the terminal .I'm Using first time expo cli i m a beginner so that's why have no idea how to fix this issue if anyone know please help me.
either you are using Mac or Ubuntu the directory you have created the project in needs superuser permissions to modify it.
either run all commands with sudo or change the ownership
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
or re-install the node with
npm install -g node#latest --unsafe-perm

Command not found with vue-cli

While installing the dependencies of vue-cli, vue is not identified. Why?
rm -rf node_modules and npm install again
have a look here
Add sudo before yarn when installing
yarn global remove #vue/cli
sudo yarn global add #vue/cli
vue
I had the same issue for a while.
TL;DR
npm install #vue/cli-service --save-dev
As the documentation specify it is a development dependency https://cli.vuejs.org/guide/#cli-service
The CLI Service (#vue/cli-service) is a development dependency. It's an npm package installed locally into every project created by #vue/cli.
Origin
I had a fresh install of nodejs
And just did
>> sudo npm install -g #vue/cli#latest
>> vue --version
#vue/cli 4.5.8
The issue
The issue presented like this
>> npm run serve
yarn run v1.22.10
$ vue-cli-service build --mode development --watch
/bin/sh: 1: vue-cli-service: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The fixes:
npm install #vue/cli-service --save-dev
Which led me straight to another error message
>> npm run serve
yarn run v1.22.10
$ vue-cli-service build --mode development --watch
ERROR Error: Cannot find module 'vue-template-compiler/package.json'
Which I fixed the same way
npm i vue-template-compiler --save-dev
And now it is working fine.
Installing current version without permanently installing vue-cli.
npx #vue/cli create appname
It shows the vue executable is located at /home/alisha/.local/bin. So probably this location is not there in your $PATH.
You should be able to run the vue commands if you provide the full path, like:
~/.local/bin/vue create hello-world
You can also see if that directory is in your PATH by running some command like:
echo $PATH | grep '.local/bin/'
If it's there, you would see it, otherwise you can add it to your path by placing it in your ~/.profile.
Edit ~/.profile and add the following at the bottom of it.
PATH="$HOME/.local/bin:$PATH"
Hope it helps!!
I had the same issue while making a build for production.
You will require vue-cli to be installed. Use below command to install the latest version.
npm install -g #vue/cli#latest
Then
npm install
Might have to do with you having an old version on your computer:
Warning regarding Previous Versions
The package name changed from vue-cli to #vue/cli. If you have the previous vue-cli (1.x or 2.x) package installed globally, you need to uninstall it first with
npm uninstall vue-cli -g or yarn global remove vue-cli.
You can find it here: https://cli.vuejs.org/guide/installation.html
THIS FIXED THE ISSUE FOR ME:
After running
sudo npm install -g #vue/cli
I ran
sudo nano $HOME/.profile
and pasted the following line
export PATH=$PATH:/home/chike/.npm-global/bin
after writing the code, next thing I did was Ctrl + O, ENTER and Ctrl + X then wrote
vue init webpack myapp
When you install vue using cli that time you got the path of vue.Now you can copy the bin folder path.
In my example /home/sublime/.npm-packages/bin
Now you export the path below command
export PATH=$PATH:/home/sublime/.npm-packages/bin
I solved mine by running (add sudo if needed)
npm i -g vue-cli#2.9.6
npm i -g #vue/cli
Got similar issue when deploy vue project in jenkins.
Here is what I did:
Add node's bin/ dir, to jenkins user's .bashrc file.
e.g
# node
NODE_HOME=/home/dev/.nvm/versions/node/default
PATH=$NODE_HOME/bin:$PATH
Tips - about nvm & yarn
When you manage node version via nvm, make sure you already choose the node version in terminal. e.g:
nvm use stable
node -v
If you use nvm, and installed yarn via npm, then better install vue-cli via npm not yarn, otherwise the vue executable is not placed into node's bin/ dir, at least that's the case in my tests, and as a result will cause you fail to find the vue command.
Using Yarn on Ubuntu it is installed to ~/.npm-packages/bin/. You must add this directory to your PATH. For example run the following command, close your terminal and open a new one.
user#machine:~$ echo 'export PATH="$PATH:~/.npm-packages/bin/"' >> ~/.bashrc
Note: if the file ~/.bashrc does not exist then simply create it.
Following worked for me:
First remove all the existing ones:
yarn global remove #vue/cli
yarn global remove #vue/cli-service
sudo yarn global remove #vue/cli
sudo yarn global remove #vue/cli-service
Then add #vue/cli using sudo:
Note: use sudo if required
yarn global add #vue/cli
yarn global add #vue/cli-service
Then, the final thing to do is to RESTART the terminal.
vue --version
#vue/cli 4.5.9
If you already got a project, the only two things you need to do is:
Delete the directory node_modules (it is safe, since it is not under git and will regenerate in the next step)
In the command-line write yarn install (it will install everything you need)
If you start installing vue-cli manually in a existing project, it the package.json and package-lock.json will be updated. If you already did. Do a checkout from git, and follow my steps above
This may be a problem caused by version conflicts. "export PATH=$PATH:" This is really useful in some cases. But if you are also like me, after trying the direct “export path” method in the comment above, restarting the terminal still can not execute the situation, you can try this way.
Uninstall Vue
npm uninstall -g #vue/cli
Check the local-global npm package installation path, vue is installed in this directory, check if it has been removed.
npm root -g
Install vue (you can check with https://cli.vuejs.org/#getting-started to find the latest command)
npm install -g #vue/cli
Create a connection to the /usr/local/bin directory(You need to find the vue.js path after the local installation first, then replace this path with your latest local install path:/Users/xxxxx/.npm-global/lib/node_modules/#vue/cli/bin/vue.js)
ln -s /Users/xxxxx/.npm-global/lib/node_modules/#vue/cli/bin/vue.js /usr/local/bin/vue
View version number
vue -v
I was getting the same error because Node.js was not installed. My issue got resolved by installing Node.js using the following command:
sudo apt install nodejs-legacy
To see if you already have Node.js and npm installed and check the installed version, run the following commands:
node -v
npm -v
If both are installed then follow the steps here:
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
I installed the package using yarn global add #vue/cli on my Ubuntu box and found the binary in /home/vonkad/.yarn/bin.
I had to modify my /home/vonkad/.bashrc and add the directory to the path export PATH=$PATH:/home/vonkad/.yarn/bin.
To fix this situation, I had to add the following line to my .zshrc (maybe in your case is .bashrc)
export PATH="$(yarn global bin):$PATH"
Effectively, the yarn global bin is a folder where vue (vue-cli 3) was placed.
What helped me
mac os catalina with zsh terminal
Uninstalled node and npm using https://www.positronx.io/how-to-uninstall-node-js-and-npm-from-macos/
Downloaded node/npm from https://nodejs.org/en/download/current/
sudo npm install -g #vue/cli
vue --version (#vue/cli 4.5.4)
I faced the same issue and now resolved. In my case I installed Node.js and NPM using the default Ubuntu repository by using this command sudo apt-get install nodejs npm
The problems seemed like those 2 packages are not well maintained so it caused some bugs.
So I purge those packages and reinstall it from nodesource which is officially recommended way to install (reference: Installation instruction from nodesource) using these commands.
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
Then reinstall #vue/cli again
sudo npm install -g #vue/cli
Now these issues have gone. Hope it helps some programmers.
You need to install vue via sudo like explained in the doc:
https://cli.vuejs.org/guide/installation.html
If you have WSL2 running and you use zsh like me, just add
yarn global add #vue/cli
# add this line to ~/.zshrc
export PATH="$HOME/.yarn/bin:$PATH"
$ vue --version
#vue/cli 4.x.xx
You can try the following code install see
npm install --global vue-cli
vue init webpack <YOUR-PROJECT-NAME-HERE>
cd <YOUR-PROJECT-NAME-HERE>
npm install
npm run dev

Yeoman, npm install errors [duplicate]

I just installed node and npm through the package on nodejs.org, and whenever I try to search or install something with npm, it throws the following error unless I sudo the command. I have a feeling this is a permissions issue? I am already the admin.
npm ERR! Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json'
npm ERR! { [Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/chietala/.npm/-/all/.cache.json' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.2.0
npm ERR! command "node" "/usr/local/bin/npm" "search" "bower"
npm ERR! cwd /Users/chietala
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Users/chietala/.npm/-/all/.cache.json
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/chietala/npm-debug.log
npm ERR! not ok code 0
This looks like a permissions issue in your home directory. To reclaim ownership of the .npm directory execute:
sudo chown -R $(whoami) ~/.npm
Permissions you used when installing Node will be required when doing things like writing in your npm directory (npm link, npm install -g, etc.).
You probably ran Node.js installation with root permissions, that's why the global package installation is asking you to be root.
Solution 1: NVM
Don't hack with permissions, install Node.js the right way.
On a development machine, you should not install and run Node.js with root permissions, otherwise things like npm link, npm install -g will need the same permissions.
NVM (Node Version Manager) allows you to install Node.js without root permissions and also allows you to install many versions of Node to play easily with them.. Perfect for development.
Uninstall Node (root permission will probably be required). This might help you.
Then install NVM following instructions on this page.
Install Node via NVM: nvm install node
Now npm link, npm install -g will no longer require you to be root.
Edit: See also https://docs.npmjs.com/getting-started/fixing-npm-permissions
Solution 2: Install packages globally for a given user
Don't hack with permissions, install npm packages globally the right way.
If you are on OSX or Linux, you can create a user dedicated directory for your global package and setup npm and node to know how to find globally installed packages.
Check out this great article for step by step instructions on installing npm modules globally without sudo.
See also: npm's documentation on Fixing npm permissions.
Also you will need the write permission in node_modules directory:
sudo chown -R $USER /usr/local/lib/node_modules
Changing the owner on "system-global" folders is a hack. On a fresh install, I would configure NPM to use an already writable location for "user-global" programs:
npm config set prefix "${HOME}/npm"
Then make sure you add that folder to your path:
export PATH="${PATH}:${HOME}/npm/bin"
To avoid future issues, do not use sudo npm ... at all.
See #ErikAndreas' answer to NPM modules won't install globally without sudo, and longer step-by-step guide by #sindresorhus with also sets $MANPATH.
Watch OUT!!! Watch OUT!!! Watch OUT!!!
chown or chmod is NOT the solution, because of security-risk.
Instead do this, do:
First check, where npm point to, if you call:
npm config get prefix
If /usr is returned, you can do the following:
mkdir ~/.npm-global
export NPM_CONFIG_PREFIX=~/.npm-global
export PATH=$PATH:~/.npm-global/bin
This create a npm-Directory in your Home-Directory and point npm to it.
To got this changes permanent, you have to add the export-command to your .bashrc:
echo -e "export NPM_CONFIG_PREFIX=~/.npm-global\nexport PATH=\$PATH:~/.npm-global/bin" >> ~/.bashrc
I encountered this when installing Recess (https://github.com/twitter/recess) to compile my CSS for Bootstrap 3.
When installing recess:
-npm install recess -g
You need to unlock permissions in your home directory, like Noah
says:
sudo chown -R `whoami` ~/.npm
You also need write permissions to the node_modules directory, like Xilo
says, so if it still isn't working, try:
sudo chown -R `whoami` /usr/local/lib/node_modules
If you are still seeing errors, you may also need to correct /usr/local permissions:
sudo chown -R `whoami` /usr/local
Please note that as indicated in this post /usr/local/ isn't actually a system dir if you are on a Mac, so, this answer is actually perfectly "safe" for Mac users. However, if you are on Linux, see Christopher Will's answer below for a multi-user friendly, system dir safe (but more complex) solution.
Other answers are suggesting to change ownerships or permissions of system directories to a specific user. I highly disadvise from doing so, this can become very awkward and might mess up the entire system!
Here is a more generic and safer approach that supports multi-user as well.
Create a new group for node-users and add the required users to this group. Then set the ownership of node-dependant files/directories to this group.
# Create new group
sudo groupadd nodegrp
# Add user to group (logname is a variable and gets replaced by the currently logged in user)
sudo usermod -a -G nodegrp `logname`
# Instant access to group without re-login
newgrp nodegrp
# Check group - nodegrp should be listed as well now
groups
# Change group of node_modules, node, npm to new group
sudo chgrp -R nodegrp /usr/lib/node_modules/
sudo chgrp nodegrp /usr/bin/node
sudo chgrp nodegrp /usr/bin/npm
# (You may want to change a couple of more files (like grunt etc) in your /usr/bin/ directory.)
Now you can easily install your modules as user
npm install -g generator-angular
Some modules (grunt, bower, yo etc.) will still need to be installed as root. This is because they create symlinks in /user/bin/.
Edit
3 years later I'd recommend to use Node Version Manager. It safes you a lot of time and trouble.
The official documentation on how to fix npm install permissions with an EACCES error is located at https://docs.npmjs.com/getting-started/fixing-npm-permissions.
I encountered this problem after a fresh install of node using the .pkg installer on OSX. There are some great answers here, but I didn't see a link to npmjs.com yet.
Option 1: Change the permission to npm's default directory
Find the path to npm's directory:
npm config get prefix
For many systems, this will be /usr/local.
WARNING: If the displayed path is just /usr, switch to Option 2.
Change the owner of npm's directories to the name of the current user (your username!):
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Option 2: Change npm's default directory to another directory
There are times when you do not want to change ownership of the default directory that npm uses (i.e. /usr) as this could cause some problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory altogether. In our case, this will be a hidden directory in our home folder.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
I ran into this issue, and while it's true that ~/.npm should be owned by your user, npm was not installing the modules there.
What actually solved my issue is these commands:
npm config set prefix ~/.npm
export PATH="$PATH:$HOME/.npm/bin"
It will make sure that all your global installation will go under this prefix. And it's important that your user owns this directory.
As if we need more answers here, but anyway..
Sindre Sorus has a guide Install npm packages globally without sudo on OS X and Linux outlining how to cleanly install without messing with permissions:
Here is a way to install packages globally for a given user.
Create a directory for your global packages
mkdir "${HOME}/.npm-packages"
Reference this directory for future usage in your .bashrc/.zshrc:
NPM_PACKAGES="${HOME}/.npm-packages"
Indicate to npm where to store your globally installed package. In your $HOME/.npmrc file add:
prefix=${HOME}/.npm-packages
Ensure node will find them. Add the following to your .bashrc/.zshrc:
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
Ensure you'll find installed binaries and man pages. Add the following to your .bashrc/.zshrc:
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
Check out npm-g_nosudo for doing the above steps automagically
Checkout the source of this guide for the latest updates.
TL;DR
always use sudo -i or sudo -H when running npm install to install global packages.
When you use npm, it downloads packages to your user home directory. When you run as sudo, npm installs files to the same directory, but now they are owned by root.
So this is what happens to absolutely every single person who has ever used npm:
install some local packages without issue using npm install foo
install global package using sudo install -g foo-cli without issue
attempt to install local package with npm install bar
get frustrated at the npm designers now that you have to go chmod a directory again
When you use the -i or -H option with sudo, your home directory will be root's home directory. Any global installs will cache packages to /root/.npm instead of root-owned files at /home/me/.npm.
Just always use sudo -i or sudo -H when running npm install to install global packages and your npm permissions problems will melt away.
For good.
--
q.v. the accepted answer for fixing an already messed up npm.
When you run npm install -g somepackage, you may get an EACCES error asking you to run the command again as root/Administrator. It's a permissions issue.
It's easy to fix, open your terminal (Applications > Utilities > Terminal)
sudo chown -R $USER /usr/local/lib/node_modules
** I strongly recommend you to not use the package management with sudo (sudo npm -g install something), because you can get some issues later **
Reference: http://foohack.com/2010/08/intro-to-npm/
I had a similar problem at NPM modules won't install globally without sudo, the issue was that when i installed node i did it with sudo via chris/lea ppa repo.
My solution was to uninstall node and then install it this way:
Download latest stable node sources from nodejs.org #in my case node-v0.10.20.tar.gz
tar -zxf node-v0.10.20.tar.gz #uncompress sources
cd node-v0.10.20 #enter uncompressed folder
sudo chown $USER -R /usr/local
./configure --prefix=/usr/local && make && make install
PD: If you don't want to change ownership of the /usr/local folder, you can install it somewhere you already own. The problem of this approach is that you will have to bind the installation folder with the bash command line so that we can use the node command later on
mkdir ~/opt
./configure --prefix=~/opt && make && make install
echo 'export PATH=~/opt/bin:${PATH}' >> ~/.bashrc #or ~/.profile or ~/.bash_profile or ~/.zshenv depending on the current Operative System
With either of those approaches, you will be able to do the following without using sudo
npm install -g module_to_install
For me, execute only
sudo chown -R $(whoami) ~/.npm
doesn't work. Then, I execute too
sudo chown -R $(whoami) /usr/lib/node_modules/
sudo chown -R $(whoami) /usr/bin/node
sudo chown -R $(whoami) /usr/bin/npm
And all works fine!
ISSUE: You (the user) don't have the right set of permissions for the directory.
The instant way out is to run the npm install using sudo, but this may give you the same error, or improper installation.
AND changing directory ownership is not a good option, a temporary patch.
Solution/Suggestion: Change npm's Default Directory (from official docs)
Back-up your computer before moving forward.
(optional) In case you have a erroneous installation, first uninstall it:
npm uninstall <package-name> # use sudo if you used it while installation
npm cache verify # or, npm cache clean for npm version below 5.x.x
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile or ~/.bash_profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables, or restart the terminal:
source ~/.profile
(optional) Test: Download a package globally without using sudo.
npm install -g jshint
For Mac (adopted from Christoper Will's answer)
Mac OS X 10.9.4
System Preference > Users & Groups > (unlock) > press + :
New Account > "Group"
Account Name : nodegrp
After creating the group, tick the user to be included in this group
sudo chgrp -R nodegrp /usr/local/lib/node_modules/
sudo chgrp nodegrp /usr/bin/node
sudo chgrp nodegrp /usr/bin/npm
sudo chown -R $(whoami):nodegrp ~/.npm
In my case,it's because of the permission of ~/tmp.So I do:
sudo chown -R $USER ~/tmp
And it's OK!
Best solution would be this which is provided by npm documentation.
For Ubuntu suggested solution is Option#2
Brief steps:
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
npm config get prefix can help you to verify if prefix was updated or not. The result would be <Your Home Directory>/.npm-global
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Instead of steps 2-4 you can also use the corresponding ENV variable
(e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
For Mac suggested solution is Option#3
On Mac OS you can avoid this problem altogether by using the Homebrew package manager
brew install node
Problem:
You do not have permission to write to the directories that npm uses to store global packages and commands.
Solution:
Allow permission for npm.
Open a terminal:
command + spacebar then type 'terminal'
Enter this command:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Note: this will require your password.
This solution allows permission to ONLY the directories needed, keeping the other directories nice and safe.
simply try
npm rebuild
then after completion run your usual command
Another great fix here to configure NPM properly, run the following commands :
npm config set prefix '~/.npm_packages'
PATH=$PATH:$HOME/.npm_packages/bin; export PATH
In case sudo chown -R $(whoami) ~/.npm didn't work for you, or you need a non terminal command solution.
The issue is that your user account does not have write permission to node_modules folder, so you can do the following
Open finder and press cmd + shift + g this will open go to folder with url
Write the following path /usr/local/lib/node_modules and press go
Right click on node_modules folder and choose Get Info
Scroll down to sharing & permissions section
Unlock to be able to make changes.
Press + and add your user account
Make sure that you choose Read & Write in privilege drop down
Now you should be able to install packages without sudo and permission issues should be solved
Nobody mentioned this, but there is actually no need to mess up with permissions or a separate npm installation, just specifying a different cache folder to the command will fix the issue
npm install --cache .npm
npm run build --cache .npm
This will create a local .npm folder
What to me seems like the best option is the one suggested in the npm documentation, which is to first check where global node_modules are installed by default by running npm config get prefix. If you get, like I do on Trusty, /usr, you might want to change it to a folder that you can safely own without messing things up the way I did.
To do that, choose or create a new folder in your system. You may want to have it in your home directory or, like me, under /usr/local for consistency because I'm also a Mac user (I prefer not to need to look into different places depending on the machine I happen to be in front of). Another good reason to do that is the fact that the /usr/local folder is probably already in your PATH (unless you like to mess around with your PATH) but chances are your newly-created folder isn't and you'd need to add it to the PATH yourself on your .bash-profile or .bashrc file.
Long story short, I changed the default location of the global modules with npm config set prefix '/usr/local', created the folder /usr/local/lib/node_modules (it will be used by npm) and changed permissions for the folders used by npm with the command:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
Now you can globally install any module safely. Hope this helps!
This is how I solved the issue on Windows 8.1:
Go to your nodejs install (usually C:\Program Files\nodejs)
Right click node_modules folder and go to properties
Click the Security tab and advanced
At the top you will see "Owner: SYSTEM", click change
Enter the user you want permissions for and click Ok
Check the box at the bottom of the advanced settings "Replace all child object permission entries with inheritable permission entries from this object" and click ok
Do whatever npm install/update you need
you could try this, works on ubuntu and mac
sudo chown -R $(whoami) /usr/local/lib/node_modules
When trying to install packages globally as root, the process will fail with EUIDLOOKUP or EACCES or npm will mess up your user global packages permissions.
To understand the problem I would suggest reading this issue. In short npm tries to use the EUID of current process to run installation scripts not as root but as the original user running npm while at the same time assuming that a user running as root would use sudo so EUID will be set.
That's why answer of #JHM16 based on using sudo should work.
But this is not the case when installing packages inside a container build. In containers sudo will be more often than not missing. And build will usually just run as root.
Of course container build can be changed to run these commands as a regular user and build everything as that user. This will not make the build more secure though and could be undesirable in some situations.
So in a container build, here's how you can make npm global install work for example with the yarn package.
# setpriv --ruid 0 --euid 0 npm --unsafe-perm install -g yarn
setpriv is a small low level utility that should be available or easily installable on any linux distro.
Actually, I was also having the same problem. I was running Ubuntu. Mine problem arises because I'd lost my public key of the Ubuntu. Even updating my system was not happening. It was giving GPG error. In that case, you can regain your key by using this command:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <key in GPG error>
After that npm works fine!
John Papa points to the history and reasoning behind this issue and gives a solid fix:
John Papa's steps are to:
Use brew to install node without npm
Update your .bash_profile/.bashrc to let npm and node know where to install and find packages
Use brew to update node and npm to update itself
Hope this helps the curious!
#Yves M.'s answer was very similar to my solution. Here are the commands I used, which were slightly different from his.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Then query for the latest version:
nvm ls-remote
Then install the newest version:
nvm install YOUR_VERSION_HERE
example
nvm install v5.8.0

How to fix EACCES issues with npm install

Some of my node modules get installed but there are always these sort of issues on this particular linux mint machine
npm install
npm ERR! Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json'
npm ERR! { [Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/me/.npm/semver/3.0.1/package/package.json',
npm ERR! parent: 'gulp' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
This code fix it for me.
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
UPDATE. See
this answer
for a better way.
You have to set correct permissions (ownership) so npm can access your (sub)directories with your normal user permissions:
sudo chown -R $USER <directory>
where in your case <directory> is /home/me and -R is for recursive to also change ownership of all your subdirectories, which is exactly what you want. That should fix the EACCESS issue.
Sadly the advise to run the command as root/Administrator is wrong here.
You want to avoid running npm with sudo ever, as recommended by the npm creator Isaac Schlueter:
I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.
See here for more details.
Add sudo before npm install . It will permit access to write .
sudo npm install [name of package].
Try to use "sudo npx create-react-app app-name"
it may still show error because some dependencies may be mising but a directory and the necessary files maybe created.
Set the correct permission to access the necessary directories.
In my case (Node & NPM Installation via Brew) on BigSur:
sudo chown -R $USER /Users/YOUR_USERNAME/node_modules
If you are still facing problem after running :
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
Run the npm install command with :
--unsafe-perm
which will help you in installing the package with out any problem.
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use 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 a ~/.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:
npm install -g jshint
(ref: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
Running the code in sudo mode have fixed the problem for me
$ sudo npm install -g nativefier
And if you have related issues like package unmet dependencies check out this link
in windows run cmd as administrator and then try:
npm install -g <package-name>
in mac os or linux try:
sudo npm install -g <package-name>
I understand one might be suspicious about changing the ownership of folders situated in the system files. But it's completely safe, they are meant to host processes that you can use without sudo. So I prefer this solution because it's good and will guarantee compatibility after.
sudo chown -R $USER /usr/local/bin
sudo chmod -R 0775 /usr/local/bin
sudo chown -R $USER /usr/local/lib/node_modules
sudo chmod -R 0775 /usr/local/lib/node_modules
If you installed a new version of node.js, you could still get some error. Try deleting the npm cache:
sudo npm cache clear
To permanently fix this problem, please run:
sudo chown -R 1000:1000 "/home/$USER/.npm"
sudo npm install -g create-react-app
just adding sudo before nmp install will give superuser privilages to run npm and that would not cause any erros while it want to alter a file or access it. well, i hope this might help you!
I had the Similar Problem when I typed:
npm install -g create-react-app
The Terminal replied:
npm ERR! code EACCES
....
So I add "sudo" like This:
sudo npm install -g create-react-app
And problem Solved!! :-)
(So I am agree with "chethan chandan" about using "sudo")