I have a lot of broken Homebrew symlinks, what do I do? - node.js

I installed node through homebrew 8 months ago.
I just tried to upgrade node through homebrew and it didnt work.
Instead, I got some message that encouraged me to run a line of code to fix it (I forget the code) but I think it broke my npm instead because my npm stopped working and I now get the error: zsh: command not found: npm when running any npm command.
I proceeded to completely uninstall node with this guide
I then began to reinstall node through homebrew with this guide
When I ran brew doctor I found that I have a lot of broken symlinks, including many npm files such as:
/usr/local/share/man/man1/npm-README.1
/usr/local/share/man/man1/npm-access.1
/usr/local/share/man/man1/npm-adduser.1
(along with about 60 other npm files and other fils including):
/usr/local/bin/grunt
/usr/local/bin/gulp
Where do I go from here? I simply want to reinstall node and npm through homebrew so that they work properly. Should I remove the broken symlinks with brew prune: or will that cause more problems for me? Thank you.

brew prune is meant for this. You can also dry run it to see what will be removed with the --dry-run flag.
prune [--dry-run]
Remove dead symlinks from the Homebrew prefix. This is generally not needed, but can be useful when doing DIY installations. Also remove broken app
symlinks from /Applications and ~/Applications that were previously created by brew linkapps.
If --dry-run or -n is passed, show what would be removed, but do not actually remove anything.

If you end up here because on the other way around you have a package installed with brew whose link seemed to disappear, relink like this:
brew unlink [package] && brew link [package]

Related

Homebrew/Node.js showing up though not installed

When I do find . -name "node*" from my root directory, I get:
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node_exporter.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodeenv.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node-sass.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#14.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#10.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodebrew.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#12.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodenv.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#16.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node-build.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#18.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/nodejs
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/node#19
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/node.js
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/nodeclipse.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/nodebox.rb
./usr/local/Homebrew/Library/Homebrew/rubocops/cask/extend/node.rb
./usr/local/Homebrew/Library/Homebrew/test/language/node_spec.rb
./usr/local/Homebrew/Library/Homebrew/language/node.rb
but brew ls doesn't show node and node -v and npm show that the commands are not installed on PATH? What's going on here?
I went through the process of
I went through the process of removing all traces of Node and npm from my own installation as npm was corrupted (was mishandling vulnerabilities), and now want to install it using brew, or in some other way so all the errors with npm when attempting to npm install don't occur. Why does brew have node installed even though I didn't install it?
Those files are not NodeJS itself, but are the instructions that tell Homebrew how to install NodeJS. You can remove those formula (along with any others that are not being used) with brew cleanup.
Edit: You cannot actually remove the formulae since those are needed if you were to install it at a later point.

How to delete node installed by brew completely?

I have a problem with uninstalling 'node' with brew.
When I used
brew uninstall node
, it showed:
Uninstalling /usr/local/Cellar/node/7.8.0... (3,076 files, 39.9MB)
; but when I commanded:
node -v
, there is still
v6.9.4
When I tried to use brew uninstall node again, it showed:
Error: No such keg: /usr/local/Cellar/node
I think I installed node package before, and today I used a wrong command:
brew install nodejs
while I actually wanted to install node. And then I found I was wrong, so I also uninstalled nodejs in the same way. But node package with lower version is still there. Anybody knows why and can help me delete it completely and reinstall?
Sounds like you may have installed node via another method in the past.
If you do
$ ls -la $(which node)
It should tell you where it's installed (and if that's symlinked to another location or not).
Removing that binary is part of the thing, the other thing you'll want to do is remove the root npm and the node_modules folder.
Find npm the same way as you found the node binary, but the root node_modules folder is probably either under /usr/local/lib but might be elsewhere; you can check npm config ls -l to get a list of all the settings of npm, which will tell you what directories to look in are.

Why is node-gyp rebuild failing on Mac OSX El Capitan

I recently bought a mac, which uses Mac OSX El Capitan v10.11.4. Installed node with homebrew, and am using node v6.2.2 and npm v3.9.5. I'm getting an error with bcrypt during npm install, which I believe derives from a node-gyp rebuild error. I also recently downloaded xcode-select(version 2343) and xcode(7.3.1) (in that order).
Here is the full error output after i run npm install:
https://gist.github.com/varunjayaraman/5734af617d616437cd5b3456b20bc503
Not sure what's going wrong. I come from linux land and do tend to be wary of not installing from source myself, so maybe that is the cause of these issues? Anyway, any advice would be super appreciated. I also saw this error springing up for others, but none of their solutions seemed to work (when i type xcode-select --print-path, I get /Applications/Xcode.app/Contents/Developer)
Anytime i upgrade OSX to newer version, I get the same issue.
Here is how i solve it every time:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
That's it. Now next time you do npm install or yarn it'll work.
PS: Sometimes you won't be able to install the command line tool through Xcode-select, for example if you are on beta.
In that case, you should be able to install it manually from here: https://developer.apple.com/download/more/
This one just bit me, too. There were a couple of different solutions, only one of which worked for me.
First, make sure you have the XCode command line tools installed, as they say on their npm page.
1) The simplest solution, which of course didn't work (though it looks like it did for some people), is to just delete the ~/.node-gyp directory. So might as well give that a shot, as well as deleting your node_modules dir and doing another npm install.
2) Try uninstalling node-gyp and re-installing:
sudo npm uninstall node-gyp -g
npm uninstall node-gyp
npm install
3) But what did the trick was a solution given in a node-gyp issue on github, where you have to install another version of node and do your npm install that way. It's easier than it sounds, but it's pretty gross:
sudo npm cache clean -f
sudo npm install -g n
sudo n 4.4.5
sudo npm install npm -g
sudo npm uninstall node-gyp -g
Then try running npm install.
Hope that helps!
If the node_modules cache was built with a recent version of Node, you may need to remove the cache, revert back and then reinstall the packages:
rm -rf node_modules
nvm use 6
npm install
I have a simple solution. If the xcode-sellect is installed try running
sudo xcode-select --reset
Same issue I had after upgrading macOS
Update brew
brew update
Update X-Code
xcode-select --install
If needed, you may have to reset the path to X-Code
xcode-select --switch /Applications/Xcode.app
xcode-select --switch /Library/Developer/CommandLineTools
For anyone who tried reinstalling Xcode tools yet the same issue persists.
You will have to go following file:
~/.node-gyp/<your_node_version_here>/include/node/common.gypi
Note: Make sure to change <you_node_version_here> to your node version like:
~/.node-gyp/16.13.1/include/node/common.gypi
You can find node version using
node -v
Inside search for key MACOSX_DEPLOYMENT_TARGET and change it's value to your current os version like mine is 11.3.1 and you will be good to go.
You can find version in
about this mac
option in drop down of mac logo
If you are using virtualenv for your python, you need to deactivate it or point npm to use the OS's own python 2 installation for node-gyp to work.
EDIT:
Had another encounter with the same bug a few days ago. This time around node-gyp was not at fault. Apparently the module I was installing has a dependency on a very old version of node-gyp (v1), independent of the system's version (v3.8), which my version of node (v10) no longer supports. Since I did not need that module anymore, I removed it. Alternatively, you may wish to upgrade/downgrade/replace the offending module, or upgrade/downgrade your node. For the OP's case, the offending module was bcrypt#0.8.5.
if you want to upgrade Node to 10 or above, you have to find dependencies out of date with Node 10 in package.json and upgrade these packages to newer stable version, then build (npm/yarn install).
Try looking at your python install.
I found a hint at the discussion here https://github.com/nodejs/node-gyp/issues/489#issuecomment-431447692.
My python on my MacBook Pro is managed by Homebrew which installs binaries to
/usr/local/bin
So I did the following in terminal:
>$: npm config set python /usr/local/bin/python
>$: rm -rf node_modules
>$: npm i
I had a similar issue.
A lot of folks have recommended that you install Xcode, and point xcode-select to the /Applications/Xcode.app/Contents/Developer. However, there is one more step.
That is to confirm that the /Applications/Xcode.app/Contents/Developer folder has SDK version corresponding to the MacOS version your actual computer is running on.
If it does not, go into /Library/Developer/CommandLineTools and copy that over.
I had a similar issue and running the commands below fixed it for me
Install xcode
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
You need to re-install XCode Tool in order to compile your codes in your machine:
* xcode-select -print-path
* sudo xcode-select --reset
* xcode-select -print-path
Here's the main link you can install it on MacOS:
https://github.com/nodejs/node-gyp/blob/main/macOS_Catalina.md

Global installation with npm doesn't work after Mac OS X Mavericks update

After upgrading to OS X 10.9 Mavericks, node wasn't found anymore in bash. I think I installed it with brew a while ago.
I decided to use the installer from node.js website. It went fine and both node and npm became available in bash. However, installing packages globally doesn't work.
The npm -g bin outputs following path /usr/local/bin.
However, after running npm install -g karma and invoking ls -la /usr/local/bin I can't see a symlink to the path where karma executable resides.
Running npm -g root returns /usr/local/lib/node_modules and after the installation I can see that karma module is there.
Not sure what I else I could check. Thanks!
I found that the root cause of all of my npm install issues was the missing Xcode license agreement.
After the Maverick update, XCode upgraded as well and if you don't launch XCode, the license agreement will be missing.
Once I accepted the agreement, installs were successful.
I had the same problem due to not accepting the xcode license after upgrading to Mavericks. I was able to accept the new xcode license by running the following:
sudo xcodebuild -license
However, npm still was not working because symlink was not created, but trying to reinstall said npm was already there. I went ahead and:
brew remove npm
and then reinstalled with:
brew install npm
and I am back working again. Not a big fan of the reinstall, but I think the need to accept the xcode license left things in a hung state.
I had the same problem - npm did not work after upgrading to mavericks. I tried all the above steps, but was still stuck. Specifically, when I tried to re-install node,
I got the error:
Warning: The post-install step did not complete successfully
You can try again using brew postinstall node
But running brew postinstall node responded:
Error: Permission denied - /usr/local/lib/node_modules/npm/AUTHORS
I tried removing all the node modules previously installed
sudo rm -rf /usr/local/lib/node_modules/
and then uninstalling and reinstalling node
and that finally got both node and npm working as before.
The problem seems to have occured because I tried to install packages that were previously on my system. The symlinks weren't created, probably because of that. Once I removed the packages and re-installed them (or tried to install packages I haven't had), they were added to /usr/local/bin as symlinks.
I had the same problem. After a maverick upgrade npm was not working, yet node itself was. I was not using the latest version as our team prefers to use 0.8.10.
In any case nvm, the node.js version manager, was still working. In this case I just reinstalled:
$ nvm install 0.8.21
######################################################################## 100.0%
Now using node v0.8.21
$ npm
Usage: npm <command>
where <command> is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, issues, la, link,
list, ll, ln, login, ls, outdated, owner, pack, prefix,
prune, publish, r, rb, rebuild, remove, restart, rm, root,
run-script, s, se, search, set, show, shrinkwrap, star,
stars, start, stop, submodule, tag, test, tst, un,
uninstall, unlink, unpublish, unstar, up, update, version,
view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm faq commonly asked questions
npm help <term> search for help on <term>
npm help npm involved overview
In the case where nvm was not working you might need to reinstall that, as well- ymmv
I am not sure if my answer was too late or not. I found myself in a difference situation than you. Hope that my experience an hour ago helps you.
my npm version (npm -v) is 1.4.28. First, I installed node.js on a computer with an administrator account. Then I created a user with administrator rights. When I tried to check the version of npm running, I failed to do so.
I searched the web and came across with this text. The original poster asked to check the path settings. I did not have node.js and npm installed with homebrew, another software that made me headache two months ago. I checked that I can run node. It is because node is located at /usr/local/bin, where all users have rights to execute programs. But for npm, it is in fact a link to ../lib/node_modules/npm/bin. However, the /usr/local/lib folder is not accessible by other users' but the administrator's account only.
I "sudo -i" and granted "chmod a+x ../lib" to it. Surprisingly, all folders' within have the correct execution right. I suspected that is some sorts of bug. I exited sudo and tried "npm -v" again. Succeed.
Hope that helps.
In case the other solutions posted here do not work for you either, you may try out the approach suggested on this GitHub page. With a complete re-installation according to the insturctions on the page, I finally got npm (and an application, vs-mda-remote to be precise) working.
EDIT: This happened after updating from Mavericks to Yosemite.

NPM appears to do nothing on Linux Mint 15

searched, and did not see this specific problem.
Trying to get a MEAN stack built on my Linux Mint machine, and bumping into a bit of an unusual issue.
Got MongoDB installed, and finally got it running correctly (none of the instructions ANYWHERE mentioned having to create the /data/db/ directory and set permissions, go figure).... it works now.
Got NodeJS installed, and it appears to work correctly.
I had been told (apparently incorrectly) that NPM installs right alongside Node, with:
sudo apt-get install nodejs
but:
$ npm
bash: /usr/bin/npm: No such file or directory
So I go ahead and install NPM separately.
$ sudo apt-get install npm
Seems to work, so far, no errors, and it looks like it is pulling down the NPM package and installing it...
$ nodejs -v
v0.10.21
$ npm -v
$
?? It simply fails to respond without any error... so I try:
$ npm install grunt -g --save-dev
$
Same completely silent failure... in fact, NOTHING I could do gets a response out of NPM.
Looked all over the web, and saw nothing similar anywhere... found out that NPM holds its cache files in ~/.npm and noticed that this folder didn't exist (kinda like the mongo issue above), so I created it, and set permissions to 7777... still nothing.
Purged and re-installed both node and npm, tried installing them both together and separately (yes, desperation)... still no love.
WTF am I doing wrong?
I would love, eventually, to have a nice development environment setup, hopefully with Cloud9 as a local IDE.... but already pulling my hair out.
=========================================================================================
OK, after a few more headaches, this is up and built now... thank you all.
Would love to mark both as answers, but it won't let me.
npm does come with node. Where is apt-get pulling it from? I install the Mac OS X packages on my Mac for development and npm does in fact come with it. I compile from source on my CentOS server and npm comes with it.
Your package provider may be providing them separately as a (in)convenience to you.
As for why your npm command does not work after installation, I can't say for sure, but I am suspicious of your use of --save-dev and -g together.
-g means to install globally, which means 2 things:
It will be installed outside of your npm package's structure into a system location like /usr/bin or /usr/local/bin
It requires root access to install. Did you use sudo to run it with root access?
Both of those requirements conflict with --save-dev which records the package as a dependency in your package.json file so that future npm install commands will install that package within the project space.
That said, I happen to know a lot about grunt. It has 2 parts, a globally installed tool and the package-specific tool. The correct way to install it is:
$ [sudo] npm install -g grunt-cli
$ npm install grunt --save-dev
This will install the grunt-cli package into a system location guaranteed to be in the $PATH, which turns around and looks for a package-specific grunt installed which is not system-wide.
When installing nodejs with npm, this one-liner worked for me.
sudo apt-get install nodejs nodejs-dev npm
I don't believe npm comes with the nodejs installation in the apt repo. Try to install npm separately using the following tutorial http://www.giantflyingsaucer.com/blog/?p=1688 'To install NPM ....'
====== Edit ====
node and npm IS separate. Follow the official wiki and everything should be fine

Resources