Set up npm global without sudo on osx - node.js

I am attempting to set up node without using sudo on my mac. I followed this link http://www.johnpapa.net/how-to-use-npm-global-without-sudo-on-osx/.
I already had node on the mac I am using. So I followed the steps for Already Have Node?
sudo rm -rf /usr/local/lib/node_modules
sudo rm -rf ~/.npm
However, the third step
brew uninstall node
Is giving me an odd error
No such keg: /usr/local/Cellar/node
I checked to see if I have homebrew with
brew help
I still have it.
It looks like that path is gone. This seems to be a common link to follow this procedure so I am not sure what I am missing. Any feedback would be much appreciated.
Thanks.

The way I have overcome this I installed node like normal using brew:
brew install node
Then I do:
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib/node_modules

Related

Node install issues on MacOS 10.14.6

I'm very new to Homebrew and Node and am having troubles getting Node up and running.
I successfully installed Homebrew, I then run brew install node and get:
Updating Homebrew...
Warning: node 13.2.0 is already installed, it's just not linked
You can use `brew link node` to link this version.
I run brew link node and get:
Linking /usr/local/Cellar/node/13.2.0...
Error: Could not symlink include/node/common.gypi
/usr/local/include/node is not writable.
Does anyone know how to fix this? Guessing it has something to do with my file not being "writable" but not sure. Thank you so much!
It seems you have a permission problem. The directories that homebrew tries to install node into have to be writable. Try this; it sets your user as owner of these subdirectories:
chown -R `whoami`:admin /usr/local/bin
chown -R `whoami`:admin /usr/local/share
chown -R `whoami`:admin /usr/local/include
and then try installing node again. You might have to brew uninstall node before brew install node.
Grab from the previous post:
$ sudo chown -R $(whoami) $(brew --prefix)/* is the solution.

npm Cannot find module 'minimatch'

I update my Node.js to 5.5.0.
But it does not work when i use npm.
It reports error:
Cannot find module 'minimatch'.
But Node.js version 4.2 is ok on my mac.
Remove this folder /usr/local/lib/node_modules/npm/node_modules/rimraf/node_modules
rm -rf /usr/local/lib/node_modules/npm/node_modules/rimraf/node_modules
This happened to me when I updated my node through the binary but also had a previous version installed through homebrew .
The way I resolved this was, uninstalling node and npm completely and reinstalling using the binary found on their website .
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
brew unlink nodejs
and reinstall .
I ran into probably the same exact problem as you.
I went from 4.2.3 LTS to 5.9, and all npm functionality ceased, always generating that error.
I had to do the following:
Uninstall Node
Save anything in your node installation folder that you may want to keep
Completely delete the node installation
Re-install 5.9
Everything was tip-top after that. I purged the folder after I noticed that there was the old 4.2.3 installer in the Installer directory. I didn't know what the ramifications of that were, but better safe than sorry.

How can I uninstall io.js correctly on Mac OS X El Capitan?

I cannot find any instructions for correctly uninstalling io.js from Mac OS X. The only guide i can find online is here, but the directory it mentions for io.js doesn't seem to exist on my computer, or I don't know where to look: https://www.binarysludge.com/2015/01/14/how-to-uninstall-io-js-or-io-js-and-node-js-together/
I think I've got a real mess with node/npm/nvm/io.js, and don't think i can start working out how to set everything up correctly unless i can figure out how to get rid of io.js.
I installed io.js using the package from the website for Mac OS X.
On the similar question was already given a detailed answer: link
For delete it run commands in terminal:
sudo npm uninstall npm -g
sudo rm -rf /usr/local/lib/node_modules /var/db/receipts/com.nodesource.iojs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node /usr/local/bin/iojs
sudo rm /usr/local/share/man/man1/iojs.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm /usr/local/share/systemtap/tapset/node.stp

can't brew install node

I am trying to upgrade my node via homebrew but ran into a problem because I think I tried to download through the website. I am very new to terminal. I've tried to search for answers but many people say you can just delete the unbrewed header files. I am not sure how to do that. but for some reason when I try to brew install node, it says the brew link step did not complete successfully.
I also tried to brew link node but that doesn't work either. I ran out of options so I came here.
[SICNARF#WOPR ~]$ brew install node
==> Downloading https://homebrew.bintray.com/bottles/node-0.12.7.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/node-0.12.7.yosemite.bottle.tar.gz
==> Pouring node-0.12.7.yosemite.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/node/android-ifaddrs.h
/usr/local/include/node is not writable.
You can try again using:
brew link node
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`
==> Summary
🍺 /usr/local/Cellar/node/0.12.7: 2726 files, 31M
this is what happens when i brew doctor
[SICNARF#WOPR ~]$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected header files:
/usr/local/include/node/ares.h
/usr/local/include/node/ares_version.h
/usr/local/include/node/libplatform/libplatform.h
/usr/local/include/node/nameser.h
/usr/local/include/node/node.h
/usr/local/include/node/node_buffer.h
/usr/local/include/node/node_internals.h
/usr/local/include/node/node_object_wrap.h
/usr/local/include/node/node_version.h
/usr/local/include/node/openssl/aes.h
/usr/local/include/node/openssl/asn1.h
/usr/local/include/node/openssl/asn1_mac.h
/usr/local/include/node/openssl/asn1t.h
/usr/local/include/node/openssl/bio.h
/usr/local/include/node/openssl/blowfish.h
/usr/local/include/node/openssl/bn.h
/usr/local/include/node/openssl/buffer.h
/usr/local/include/node/openssl/camellia.h
/usr/local/include/node/openssl/cast.h
/usr/local/include/node/openssl/cmac.h
/usr/local/include/node/openssl/cms.h
/usr/local/include/node/openssl/comp.h
/usr/local/include/node/openssl/conf.h
/usr/local/include/node/openssl/conf_api.h
/usr/local/include/node/openssl/crypto.h
/usr/local/include/node/openssl/des.h
/usr/local/include/node/openssl/des_old.h
/usr/local/include/node/openssl/dh.h
/usr/local/include/node/openssl/dsa.h
/usr/local/include/node/openssl/dso.h
/usr/local/include/node/openssl/dtls1.h
/usr/local/include/node/openssl/e_os2.h
/usr/local/include/node/openssl/ebcdic.h
/usr/local/include/node/openssl/ec.h
/usr/local/include/node/openssl/ecdh.h
/usr/local/include/node/openssl/ecdsa.h
/usr/local/include/node/openssl/engine.h
/usr/local/include/node/openssl/err.h
/usr/local/include/node/openssl/evp.h
/usr/local/include/node/openssl/hmac.h
/usr/local/include/node/openssl/idea.h
/usr/local/include/node/openssl/krb5_asn.h
/usr/local/include/node/openssl/kssl.h
/usr/local/include/node/openssl/lhash.h
/usr/local/include/node/openssl/md4.h
/usr/local/include/node/openssl/md5.h
/usr/local/include/node/openssl/mdc2.h
/usr/local/include/node/openssl/modes.h
/usr/local/include/node/openssl/obj_mac.h
/usr/local/include/node/openssl/objects.h
/usr/local/include/node/openssl/ocsp.h
/usr/local/include/node/openssl/opensslconf.h
/usr/local/include/node/openssl/opensslv.h
/usr/local/include/node/openssl/ossl_typ.h
/usr/local/include/node/openssl/pem.h
/usr/local/include/node/openssl/pem2.h
/usr/local/include/node/openssl/pkcs12.h
/usr/local/include/node/openssl/pkcs7.h
/usr/local/include/node/openssl/pqueue.h
/usr/local/include/node/openssl/rand.h
/usr/local/include/node/openssl/rc2.h
/usr/local/include/node/openssl/rc4.h
/usr/local/include/node/openssl/ripemd.h
/usr/local/include/node/openssl/rsa.h
/usr/local/include/node/openssl/safestack.h
/usr/local/include/node/openssl/seed.h
/usr/local/include/node/openssl/sha.h
/usr/local/include/node/openssl/srp.h
/usr/local/include/node/openssl/srtp.h
/usr/local/include/node/openssl/ssl.h
/usr/local/include/node/openssl/ssl2.h
/usr/local/include/node/openssl/ssl23.h
/usr/local/include/node/openssl/ssl3.h
/usr/local/include/node/openssl/stack.h
/usr/local/include/node/openssl/symhacks.h
/usr/local/include/node/openssl/tls1.h
/usr/local/include/node/openssl/ts.h
/usr/local/include/node/openssl/txt_db.h
/usr/local/include/node/openssl/ui.h
/usr/local/include/node/openssl/ui_compat.h
/usr/local/include/node/openssl/whrlpool.h
/usr/local/include/node/openssl/x509.h
/usr/local/include/node/openssl/x509_vfy.h
/usr/local/include/node/openssl/x509v3.h
/usr/local/include/node/pthread-fixes.h
/usr/local/include/node/smalloc.h
/usr/local/include/node/stdint-msvc2008.h
/usr/local/include/node/tree.h
/usr/local/include/node/uv-aix.h
/usr/local/include/node/uv-bsd.h
/usr/local/include/node/uv-darwin.h
/usr/local/include/node/uv-errno.h
/usr/local/include/node/uv-linux.h
/usr/local/include/node/uv-sunos.h
/usr/local/include/node/uv-threadpool.h
/usr/local/include/node/uv-unix.h
/usr/local/include/node/uv-version.h
/usr/local/include/node/uv-win.h
/usr/local/include/node/uv.h
/usr/local/include/node/v8-debug.h
/usr/local/include/node/v8-platform.h
/usr/local/include/node/v8-profiler.h
/usr/local/include/node/v8-testing.h
/usr/local/include/node/v8-util.h
/usr/local/include/node/v8.h
/usr/local/include/node/v8config.h
/usr/local/include/node/v8stdint.h
/usr/local/include/node/zconf.h
/usr/local/include/node/zlib.h
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
node
[SICNARF#WOPR ~]$ brew link
This command requires a keg argument
[SICNARF#WOPR ~]$ brew link node
Linking /usr/local/Cellar/node/0.12.7...
Error: Could not symlink include/node/android-ifaddrs.h
/usr/local/include/node is not writable.
There are two steps involved.
Simply run these four commands:
sudo chown -R `whoami`:admin /usr/local/include/node
sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
sudo chown -R `whoami`:admin /usr/local/lib/dtrace
Finally, run the overwrite command:
brew link --overwrite node
I ran into this same issue under the same circumstances. I was able to get the brew version to install successfully by:
Run brew install node
Make note of the module that is causing the issue and delete it. In your case, this would be /usr/local/include/node
Uninstall - brew uninstall node
Re-install - brew install node
I had to repeat this process a few times for each remaining problematic directory (about 3 different ones in actuality), and the install eventually succeeded without any issues.
I ran into this problem on a new MacBook Pro on Mac OS High Sierra. I gleaned brew was trying to use directories named include and lib under /usr/local that was not there. Since root owns /usr I had to do it manually - making sure that whoami owner matches peer directories in /usr/local:
sudo mkdir /usr/local/include
chown `whoami`:admin /usr/local/include
sudo mkdir /usr/local/lib
chown `whoami`:admin /usr/local/lib
And then to match the other directories in /usr/local I did:
chmod 775 /usr/local/include
chmod 775 /usr/local/lib
then the following worked:
brew uninstall node
brew install node
You need to make /usr/local/bin and /usr/local/share writable. I used this answer to achieve this. Below is the key advice in the answer replicated in case the link breaks:
sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
I had the same error:
Linking /usr/local/Cellar/node/11.10.0...
Error: Could not symlink include/node /usr/local/include is not writable.
Solution:
$ sudo mkdir /usr/local/include
$ sudo chown -R $(whoami) $(brew --prefix)/*
$ brew link node
Linking /usr/local/Cellar/node/11.10.0... 7 symlinks created
$ node -v => v11.10.0
$ npm -v => 6.7.0
brew postinstall node or brew link --overwrite node doesn't seem to help.
After several rounds of brew uninstall node and brew install node the following were the offending directories and files:
sudo rm -r /usr/local/include/node
sudo rm -r /usr/local/share/doc/node
sudo rm -r /usr/local/lib/node_modules
sudo rm /usr/local/lib/dtrace/node.d
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/share/systemtap/tapset/node.stp
After the offending files are removed brew will do all the proper linking with permissions for you.
Likely permissions were set as root:wheel because of a past install with sudo or perhaps manual installation, etc.
For those running high sierra on MacOS:
I tried giving permissions using the chown command and uninstalling then reinstalling node via homebrew but nothing worked.
I just went to this site https://nodejs.org/en/download/ and downloaded the 64 bit macOS .pkg and it worked perfectly. I tested it by just entering the command node in terminal.
I had a very similar problem with linking. I couldn't get it to work. I tried to chmod /usr/local/include/node so I could write the link to it but ran into another error. As a final solution, I just reinstalled node from https://nodejs.org/download/
I have a working node prompt again! I would love to go through brew to update but it saved me a lot of hassle just using the pkg installer from the site. I know this may not be the solution you are looking for but I just wanted to share my experience with the same issue. I hope it helps!
brew link --overwrite node
Error: Could not symlink (...)
/usr/xxx
sudo chown -R 'whoami?':admin xxx
brew link --overwrite node
Rinse and repeat
For me I had to run brew doctor which showed me that I did not have write access and had to run sudo chown -R $(whoami) /usr/local/bin /usr/local/share /usr/local/share/man to fix the issue.
I suggest running brew doctor to see if it can provide some hints on the issue
remove the error folder or file manually and run this command brew uninstall node && brew install node
You have to do this process till all error folder and files are removed.
Then node will be linked.
If you try to brew link node and it says something along the lines:
Error: Could not symlink include/node/openssl/archs/aix-gcc/asm/include/openssl/opensslconf.h
Target /usr/local/include/node/openssl/archs/aix-gcc/asm/include/openssl/opensslconf.h
already exists. You may want to remove it:
Try this:
brew link --overwrite --dry-run node | xargs rm
brew link node

Uninstall Node.JS using Linux command line?

How do you uninstall node.js using the cmd line in linux?
For Ubuntu 12.04:
sudo apt-get remove nodejs
This will uninstall nodejs as well as npm.
Edit: If you know which package manager was used to install, it is best to uninstall with the same package manager. Examples for apt, make, yum are in other answers.
This is a manual approach:
Running which node will return something like /path/bin/node.
Then run cd /path
This is all that is added by Node.JS.
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Now the only thing I don't know about is npm and what it has installed. If you install npm again into a custom path that starts off empty, then you can see what it adds and then you will be able to make a list for npm similar to the above list I made for node.
If you installed from source, you can issue the following command:
sudo make uninstall
If you followed the instructions on https://github.com/nodejs/node/wiki to install to your $HOME/local/node, then you have to type the following before the line above:
./configure --prefix=$HOME/local/node
Sorry the answer of George Bailey does work very fine when you
want absolutely remove the node from your machine.
This answer is referred from : #tedeh
https://github.com/nodesource/distributions/issues/486
If you wanna install a new version of node you have to use the code below
sudo rm -rf /var/cache/yum
sudo yum remove -y nodejs
sudo rm /etc/yum.repos.d/nodesource*
sudo yum clean all
And add new nodejs version to "yum" an new version of node
#using this command for Node version 8
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
#using this command for Node version 10
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
Install nodejs
sudo yum -y install nodejs
I hope it gonna help you guy!!!
To uninstall node I followed the accepted answer by #George, as I no longer have the sources, but before doing so I ran:
sudo npm rm npm -g
That seemed to get rid of npm from the system directories such as /usr/bin/npm and /usr/lib/npm. I got the command from here. I then found a ~/.npm directory, which I deleted manually. Honestly I don't know if every trace of npm has been removed, but I can't find anything else.
If you installed node using curl + yum:
sudo curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
sudo yum -y install nodejs
Then you can remove it using yum:
sudo yum remove nodejs
Note that using the curl script causes the wrong version of node to be installed. There is a bug that causes node v6.7 to be installed instead of v4.x intended by the path (../setup_4.x) used in the curl script.
This is better to remove NodeJS and its modules manually because installation leaves a lot of files, links and modules behind and later it create problems while we reconfigure another version of NodeJS and its modules.
Run the following commands.
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/include/node*
sudo rm -rf /usr/local/bin/node*
and this done.
A step by step guide with commands is at http://amcositsupport.blogspot.in/2016/07/to-completely-uninstall-node-js-from.html
This helped me resolve my problem.
I think Manoj Gupta had the best answer from what I'm seeing. However, the remove command doesn't get rid of any configuration folders or files that may be leftover. Use:
sudo apt-get purge --auto-remove nodejs
The purge command should remove the package and then clean up any configuration files. (see this question for more info on the difference between purge and remove). The auto-remove flag will do the same for packages that were installed by NodeJS.
See the accepted answer on this question for a better explanation.
Although don't forget to handle NPM! Josh's answer covers that.
The answer of George Bailey works fine.
I would just add the following flags and use sudo if needed:
sudo rm -rf bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node
if you want to just update node, there's a neat updater too
https://github.com/creationix/nvm
to use,
git clone git://github.com/creationix/nvm.git ~/.nvm
source ~/.nvm/nvm.sh
nvm install v0.4.1
I think this works, at least partially (have not investigated):
nvm uninstall <VERSION_TO_UNINSTALL>
eg:
nvm uninstall 4.4.5
If you have yum you could do:
yum remove nodesource-release* nodejs
yum clean all
And after that check if its deleted:
rpm -qa 'node|npm'
after installing using the "ROCK-SOLID NODE.JS PLATFORM ON UBUNTU" script, i get this output. Which tells you how to uninstall nodejs.
Done. The new package has been installed and saved to
/tmp/node-install/node-v0.8.19/nodejs_0.8.19-1_i386.deb
You can remove it from your system anytime using:
dpkg -r nodejs
Best way to go around this is to do it right from the BEGINNING:
INSTALL BREW
#HERE IS HOW: PASTE IN TERMINAL
sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
Then at the end of your .bashrc file(In your home directory press Ctrl + H)
export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"
Then restart terminal so the modification to .bashrc are reloaded
TO INSTALL NODE
brew install node
TO CHECK VERSION
node -v
npm -v
TO UPDATE NODE
brew update
brew upgrade node
TO UNINSTALL NODE
brew uninstall node
To Remove nodejs installed in centos 8:
From your home directory, run the below command
sudo yum remove nodejs
Enter y to confirm your command
In addition to apt or yum removal, clean any residual files to avoid conflicts if you ever install a new version:
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/share/man/man1/node*
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm -rf /opt/local/bin/node
sudo rm -rf opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/include/node*
sudo rm -rf /usr/local/bin/node*
For Centos 7 and 8
Remove NodeJS
sudo yum remove -y nodejs
sudo rm -rf /var/cache/yum
sudo rm /etc/yum.repos.d/nodesource*
sudo yum clean all
Remove residual files
whereis node
sudo rm -rfv /usr/bin/node /usr/local/bin/node /usr/share/man/man1/node.1.gz
sudo rm -rfv /usr/bin/npm /usr/local/bin/npm /usr/share/man/man1/npm.1.gz
sudo rm -rfv /usr/local/bin/npx
sudo rm -rfv /usr/local/lib/node*
sudo rm -rfv /usr/local/include/node*
sudo rm -rfv /usr/lib/node_modules/
Just remove these files. No need to do anything else.
rm -rf ~/.nvm
rm -rf ~/.npm
rm -rf ~/.bower

Resources