Node command refers to older version - node.js

Hello when I use the node command on my Mac. It refers to an older version:
-bash: /usr/local/opt/node#14/bin/node: No such file or directory
I have removed node 14 and later installed the latest version of node with brew install node.
How can I make that the node command refers to the latest version?

Generally, this issue can be uncovered by brew doctor run.
But like Andreas said, it should be resolved by brew link --overwrite node to fix the node symlink.
If you just need node, you can use nvm to manage the different node versions for different applications, and you can also use .node-version to specify this metadata.

You might have some invalid symlink pointing to the old version. Especially with version-specific packages, this can be the case. You might first check where your node executable is referenced from by running which node to make sure if the symlink comes from brew (usually using /usr/local/bin/node) and list the details of the link by e.g. ls -la $(which node).
To fix the link to point to the package you want, you can run
brew link node
Maybe this requires some force...
brew link --force node.
For details check this answer on apple stackexchange

Related

Updating to stable version of nodejs with n

this is my first time trying to update the nodejs version of a unix server. I want to use it to create a react app, and facing the following:
>npx create-react-app test
You are running Node 8.11.3.
Create React App requires Node 10 or higher.
Please update your version of Node.
So I have tried to update the version with the following commands:
>sudo npm cache clean -f
>sudo npm install -g n
>sudo n stable
installed : v14.15.4 to /usr/local/bin/node
active : v8.11.3 at /bin/node
However it seems that didn't upgrade the version, it installed a different version in a different path.
I am not sure if it is possible just to upgrade the version that is already active, I prefer not to do a workaround and just upgrade it directly.
As complementary information if I run n doctor I see the following:
>n doctor
Checking n install destination is in PATH...
'/usr/local/bin' is not in PATH
As I said previously, what I am looking for is a safe way to update the version already installed to be able to use create-react-app, being able to rollback to previous version easily if something doesn't work, I understand that the way is using n.
Thanks in advance.
I suggest you add /usr/local/bin to the start of your PATH (so it comes before /bin).
I do not recommend you try and overwrite /bin/node using n. Something else installed /bin/node in a system directory, and overwriting it using n could leave things in a mixed and confused state. n installs to /usr/local by default, but you can set N_PREFIX to install to your home folder, for example.
To avoid confusion with having two versions of node installed, you may wish to uninstall the /bin version, likely installed by your platform package manager.
Tip: Changing where node and npm are installed is likely to change where your global npm packages are installed. I suggest you list what you have installed now in case you want to reinstall then in the "new" location. npm list -g --depth=0

Cannot find Typescript using NVM

I have nvm installed and recently fixed an issue with a conflict with a previously installed version of node. Fixing it meant removing the node executable from the prior location. Some things still work but I'm getting this error:
Cannot find module 'typescript'
and this fix didn't help me:
How to fix Cannot find module 'typescript' in Angular 4?
running ng new is what is triggering the error.
I have typescript installed globally. And to ensure that is installed with this version of node, I ran:
nvm use 10 && npm i -g typescript
/Users/username/.nvm/versions/node/v10.16.0/lib/node_modules/typescript/bin/tsserver
Thanks,
Wayne
When using nvm, every node version has it's own globally installed dependencies. If you are not finding something you have installed previously for a different version of node (or you have removed it), this can be a reason.
For anyone coming across this question, I found the answer here.
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
I had to do all of the steps in the most accepted answer. I also had to:
rm -Rf /user/local/bin/node_modules
It might be a good idea to search your machine for all node_modules folders and, of course, ignore any "local" versions. And delete all of them that are not in your nvm directory. That directory will look somehting like:
/Users/username/.nvm/versions/node/v#####/lib/node_modules
You can identify yours using:
npm root -g

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.

Updating node and npm using Homebrew

I want to upgrade npm but I need Node version >0.10.32
Typing $ brew upgrade node I get:
Error: node 7.2.1 already installed
but with $ node -v I get:
v0.10.24
Why are there two version formats and how can I get node updated to the required version?
I need
You have two different versions of Node installed in different paths.
The one in the directory closer to the front of your $PATH environment variable is 0.10.24.
The one installed by brew is 7.2.1.
If you want to use the brew managed one, then the easiest thing to do is to uninstall the other version.
Alternatively, use the full path to the brew managed one.

Managing global npm packages when using nvm

I feel like I need to be able to install global npm packages separately into the NVM dir.
$ nvm install v0.11
######################################################################## 100.0%
Now using node v0.11.16
$ node-inspector
Node Inspector v0.9.2
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
my node-inspector stopped working!
$ npm update -g
<bunch of updating, succeeds>
Maybe this will help... Nope! still broken.
Sigh. Perhaps... node-inspector doesn't work for a v0.11.16 (that's being run on nvm). Perhaps. Who knows. Well, time to abort.
$ nvm use system
Now using system version of node: v0.10.32.
$ node-inspector --version
dyld: lazy symbol binding failed: Symbol not found: _node_module_register
Referenced from: /usr/local/lib/node_modules/node-inspector/node_modules/ws/build/Release/bufferutil.node
Expected in: dynamic lookup
dyld: Symbol not found: _node_module_register
Referenced from: /usr/local/lib/node_modules/node-inspector/node_modules/ws/build/Release/bufferutil.node
Expected in: dynamic lookup
[1] 93845 trace trap node-inspector --version
Okay.... Well.... Shit.
So anyway, at this point I'm not looking for instructions on how to fix. I may well be hosed. The main question here is what am I supposed to do to manage these npm packages which are meant to be command line tools and which have compiled components that appear tied to specific versions? I understand that when I install nvm and incorporate it into my system, my shell is able to switch its $PATH so that when I call node and npm, they will run using the node version I picked.
But it appears as though the global npm packages get put into /usr/local/bin/ somewhere and they're just stuck there and become unable to follow what I do with nvm -- While it may not be the case for the "theoretically well-behaved node package", in practice (for something like node-inspector at least) it sure looks like it's liable to gleefully explode when not executed using the node that installed it.
In the meantime I have to basically npm remove -g <package> && npm install -g <package> any package that I find behaves strangely in this manner, every single time that I want to run that package under a new node version using nvm.
This seems wrong.
Is it wrong?
And, a corollary to this would be that every time I invoke nvm powers to test some given node.js app with a different version of node, I pretty much should do it by cloning it in a whole new directory and starting fresh, because otherwise I'll probably find out that I will need to rm -rf node_modules && npm install just to make it function at all...
UPDATE October 2020:
If you've already installed the desired Node version, according to the documentation this is also available:
nvm reinstall-packages <from-version>
Props to #rashi for pointing out the syntax above.
From the nvm help message:
nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available
--reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>
--lts When installing, only select from LTS (long-term support) versions
--lts=<LTS name> When installing, only select from versions for a specific LTS line
The relevant flag is --reinstall-packages-from=<version>. Simply re-run your command (example):
$ nvm install v6.9.2 --reinstall-packages-from=v4.4.5
I may have misunderstood your situation, but it seems like you need to install all global packages you use separately for each node version you are using. The reason it works like that is that you may need different versions of packages for different node versions. So whenever you use nvm use ... it changes paths to global packages to the packages installed for the selected version of node.
Hope it helps.

Resources