For example I want to install either 7.9 or 7.10 but want to avoid Node 8 due to the webpack node-sass breaking bug.
When I run brew search node this is what I see:
❯ brew search node
leafnode llnode node ✔ node-build > node#0.10 node#0.12 node#4 node#6 nodebrew nodeenv nodenv
caskroom/cask/node-profiler
If you meant "node" specifically:
It was migrated from caskroom/cask to homebrew/core.
You can access it again by running:
brew tap homebrew/core
There is node which is checked (my current version is v7.4.0 then node#0.10, node#0.12, node#4 and node#6?
The reason I can't just fully upgrade to 8 is node-sass won't work in webpack.
Just installed NVM and got this crazy error log:
=> nvm source string already in /Users/leongaban/.zshrc
=> Appending bash_completion source string to /Users/leongaban/.zshrc
npm ERR! missing: is-path-cwd#^1.0.0, required by del#3.0.0
npm ERR! missing: is-path-in-cwd#^1.0.0, required by del#3.0.0
npm ERR! missing: p-map#^1.1.1, required by del#3.0.0
npm ERR! missing: pify#^3.0.0, required by del#3.0.0
npm ERR! missing: rimraf#^2.2.8, required by del#3.0.0
npm ERR! missing: bluebird#^3.1.1, required by gulp-html-replace#1.6.2
npm ERR! missing: clone#^1.0.2, required by gulp-html-replace#1.6.2
...
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:
If I'm reading this right, does this mean I can't use npm to globally install packages anymore and have to use nvm?
Update
I added the export lines to my .zshrc bash (I don't use bash_profile)
❯ nvm --version
0.33.2
There are two ways in the decision for using different version of Node. Second way is more convenient and practical by my opinion (also may be faster).
First way:
Install other Node version(for example 14) with using:
brew install
brew unlink
brew link
brew install - github
brew unlink - github
brew link - github
brew install node#14
brew unlink node
brew link node#14
node -v
PS You may use brew link with flag --overwrite, for example:
brew link --overwrite node#14
PS2 Why unlink and then link again?
Documentation:
Remove symlinks for formula from Homebrew's prefix. This can be
useful for temporarily disabling a formula:
brew unlink formula && commands && brew link formula
In other words:
if you have both node and node#14 installed, where node is other version(..,15 or 16), so, for set active version 14:
you must unlink node
and then link to new installed version 14
brew unlink node
brew link node#14
Second way:
Install Node Version Manager(nvm) and select Node version:
nvm - github nvm - home brew
brew install nvm
mkdir ~/.nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$(brew --prefix)/opt/nvm/nvm.sh" ] && . "$(brew --prefix)/opt/nvm/nvm.sh" # This loads nvm
[ -s "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" ] && . "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
nvm install 14
nvm use 14
nvm list
If versions on homebrew/code are defined right, you must also be able to brew install node#0.12 for example.
You can also install multiple versions and select which one you want to use with the brew switch command.
--
Anyway, I'd recommend using nvm, which can be installed through Homebrew. Although, the version on brew is buggy and they don't plan fixing it.
To install the latest version of node and unlink the previously installed
brew install node#14
brew unlink node
brew link --overwrite node#14
echo 'export PATH="/usr/local/opt/node#14/bin:$PATH"' >> ~/.bash_profile
node -v
brew install --build-from-source node#14
Related
As per the yarn installation for yarn v2, they want you to install using npm install -g yarn. So I ran sudo npm install -g yarn on Ubuntu 20.04. But after I do that, it says command not found.
❯ sudo npm install -g yarn
> yarn#1.22.10 preinstall /usr/local/lib/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)
❯ yarn --version
zsh: command not found: yarn
sudo npm install -g npm
then
sudo npm install -g yarn
Then reboot your system. That did it for me.
Before a reboot only sudo yarn worked. I tried looking at file permissions but everything seemed in order and the files were executable as expected. Nevertheless after a reboot it worked.
If you go to /usr/local/bin after the installation there's a link there to where yarn.js lives, as expected, and file permissions for it were also correct.
/usr/local/bin is added to $PATH, so it's surprising that it doesn't see the new cmd right away, but perhaps it didn't reload or map it until after the reboot? I don't know. But I just spent a good hour trying to figure this out so I'm posting what worked for me to spare other the hassle.
TL;DR
If you are managing node via nvm, then probably the path to yarn binary is not included in the $PATH variable. You should add this -
# Add this at the end (or after the $NVM_DIR initialization)
# in your profile - .bashrc | .zshrc | .profile, etc
export PATH="`yarn global bin`:$PATH"
at the end of your profile file (.zshrc for me) or at least after the $NVM_DIR initialization.
I have recently faced this issue and while searching for a solution, I landed up here.
Here is what my environment looks like:
OS: Ubuntu 20.04
Shell: zsh
NodeJS: managing it via nvm, and NOT apt.
After going through all the answers, I was not keen on uninstalling anything. So I tried to dig a bit deeper.
I installed yarn via npm install -g yarn command. So the first thing I wanted to verify was the location of the yarn binary. To do this, I ran the command where yarn which lists the installation path for the yarn binary.
$ where yarn
/home/<user_name>/.nvm/versions/node/v16.11.1/bin/yarn
Then it hit me. In my .zshrc file, I had added the yarn global bin command (which spills out the directory of all the global packages installed by yarn) at the top like so:
# Top of my .zshrc file
export PATH="`yarn global bin`:$HOME/bin:/usr/local/bin:$PATH"
and as per the installation instruction of nvm, the $NVM_DIR (the variable which holds the nvm directory path) was added at the end of my .zshrc file.
So when I was starting up my shell, it was actually trying to load the yarn command (present inside the nvm directory) even before loading the $NVM_DIR path.
To solve this, I tweaked my .zshrc file and moved the yarn global bin command after the $NVM_DIR like this:
# Top of my .zshrc file
export PATH="$HOME/bin:/usr/local/bin:$PATH"
# ...
#
# Something in between
#
# ...
# Bottom of my .zshrc file
export NVM_DIR="${HOME}/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Here is where I have added the path to yarn global
export PATH="`yarn global bin`:$$PATH"
I hope that this would be of help.
This solved it for me:
corepack enable
(if you get "Internal Error: EACCES: permission denied", run it with sudo)
This is also recommended by the Yarn documentation: https://yarnpkg.com/getting-started/install
Uninstall cmdtest:
sudo apt remove cmdtest
Then, run these commands:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
If you want to avoid reboot, use
/usr/local/lib/node_modules/yarn/bin/yarn --version
The yarn documentation is missing a step, you need to restart your computer between this installation and running yarn --version.
This worked for me
I recently had a similar situation and here is how I solved it.
First I troubleshoot the current npm installation:
npm config -list
I had a ~/.npmrc file that had a different prefix:
PREFIX=/opt/homebrew
That made my npm installation look for globally installed packages under /opt/homebrew.
In my case, I'm using a different npm installation (not with homebrew anymore). A simple fix is to remove this custom PREFIX from the ~/.npmrc file and the problem was solved.
Now npm looks for globally installed packages under /usr/local/bin/.
I installed yarn with npm install -g yarn on git bash and I tested it with yarn -v that show the version of the installed yarn, but when I used yarn start it gives me this error
C:\Users\{username}\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found
These are simple steps that I used to fix my problem on Windows 10:
Uninstall node.js
Restart your computer
Delete your C:\Program Files\nodejs and C:\Users\{username}\AppData\Roaming\npm
Install node.js again and check it with node -v
Start your vs code as an admin and write npm install
Write yarn start
I am getting a TypeError when running npm install -g react-native project on mac.
full error
TypeError: Cannot destructure property stat of 'undefined' or 'null'.
at Object. (/usr/local/lib/node_modules/npm/node_modules/#npmcli/node-gyp/lib/index.js:2:29)
Might be you are using npm#latest. Looks to me some issue with lates NPM, I have changed my version with RUN npm install npm#6.14.11 -g in my docker file working for me.
When I upgraded to Big Sur, I had the same issue. It's something to do with npm, not react-native.
Here's what I did to solve the problem:
Delete everything related to nodejs:
sudo rm -rf ~/.npm ~/.nvm ~/node_modules ~/.node-gyp ~/.npmrc ~/.node_repl_history
sudo rm -rf /usr/local/bin/npm /usr/local/bin/node-debug /usr/local/bin/node /usr/local/bin/node-gyp
sudo rm -rf /usr/local/share/man/man1/node* /usr/local/share/man/man1/npm*
sudo rm -rf /usr/local/include/node /usr/local/include/node_modules
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/lib/dtrace/node.d
sudo rm -rf /opt/local/include/node /opt/local/bin/node /opt/local/lib/node
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/share/systemtap/tapset/node.stp
brew uninstall node
brew doctor
brew cleanup --prune-prefix
And then install nvm again via:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Now, I was able to install all of my dependencies since now I've got a fresh copy of npm(for me it was 6.4.1).
As usual, Mac OS updates tend to break stuff.
In case you're using NVM too (like me).
I faced this issue too and found that NVM is using a node version called 'system'. I never seen it before and NVM should be using the version I set it to use.
So I decided to update NVM. (See: https://github.com/nvm-sh/nvm/blob/master/README.md#installing-and-updating)
Seems to work after that.
You shouldn't be using npm install -g react-native.
Please read through the React Native docs on how to do your environment setup: https://reactnative.dev/docs/environment-setup
In case that you have the same error when running any command that has npm, you might have wrong npm version with node 8.
Running this will reverse your npm to node 6.
curl -qs https://www.npmjs.com/install.sh|npm_install=6.14.11 sh
Reference:
https://github.com/npm/cli/issues/2599
why i use npm to install something, it will have this problem as below
ERROR: npm is known not to run on Node.js v9.2.1
Node.js 9 is supported but the specific version you're running has
a bug known to break npm. Please update to at least 9.0.0 to use this
version of npm. You can find the latest release of Node.js at https://nodejs.org/
Then i find some solutions at stackoverflow.
npm WARN npm npm does not support Node.js v9.1.0
npm does not support Node.js v9.0.0
Almost every answer suggest to use "npm uninstall -g npm" first.But when i use this command,it will have the same error as above.
My npm version is 6.13.7
My node version is 9.2.
Basically node js 9.2... version is compatible with npm version 5.5.1.
So I will provide you the following suggestion.
1- if you want to work with node js 9.2 only then
i)- uninstall node js 9.2
ii)- uninstall npm
iii)- install node js 9.2
iv)- then install npm version 5.5.1
npm install -g npm#5.5.1
2- update node js and npm to the latest version and check your code compatibility with the new version.
To do this
1- install node js latest version
2-npm install -g npm#latest
I followed the documentation to create my first NestJS project.
Installing the Nest CLI with the command npm i -g #nestjs/cli was successful.
The output was:
+ #nestjs/cli#6.3.0
updated 1 package in 11.326s
However, when I try to scaffold a project with the Nest CLI:
nest new project-name
I get the following error:
zsh: command not found: nest
Some details about my environment:
OSX
iTerm
npm version 6.5.0
Use npx #nestjs/cli instead of nest
e.g. npx #nestjs/cli g controller pages
I was also getting the same console error when npm installing!
Erro was
#nestjs/cli
npm WARN deprecated resolve-url#0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix#0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated chokidar#2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated fsevents#1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/#nestjs/cli
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/#nestjs
npm WARN notsup Unsupported engine for watchpack-chokidar2#2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"12.14.1","npm":"6.13.4"})
npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2#2.0.0
How I wasn able to install =>
Solution
sudo npm install -g #nestjs/cli
Following command works in my windows 10
node -v
v14.16.0
npm -v
6.14.11
npx #nestjs/cli new project-name
I was having the same issue, what I did was:
Installed the latest node with npm install npm#latest -g
and then added the following to my .bash_profile
alias nest="/usr/local/Cellar/node/11.9.0/bin/nest"
Tested with nest --version and it worked.
For some reason the path is not being called correctly, hope it helps.
Working through a NestJS/Mongo DB tutorial i stumbled into this very same problem. After trying all of the solutions that were listed above, even turning my default profile back to bash instead of using zsh, i found that simply adding the /usr/local/bin and ~/.npm-global/bin to my path variable resolved the issue. Hopefully this helps someone else who may stumble on this in the future as well.
export $PATH="/usr/local/bin"
export $PATH="~/.npm-global/bin"
Were the two commands i ran from iTerm2 in order to add them to my PATH environment variable. Once this was done a simple
env
showed the entries in my $PATH environment variable and the nest -v command worked without any issues.
I had same error when I use GitBash.
I resoved it:
If you use windows:
Your use CMD: npm i -g #nestjs/cli
Then you can use gitbash:
Check version nestjs: nest --version
Create app nestjs: nest new name_project
I have faced same problem and solved ,following this
write the command NPM root -g
check where NPM is installed
add it to your path environment variable
You have to add the following line to your ~/.zshrc file:
source $HOME/.bashrc
This is needed so that the npm binaries are available on startup.
After all the answers that I tried, I used my method
After installing npm i -g #nestjs/cli in my mac terminal.
open bash file in macos by typing open ~/.bash_profile in mac terminal. Like you can type it anywhere.
Your bash will look like this and use this line
alias nest="~/.npm-global/lib/node_modules/#nestjs/cli/bin/nest.js"
Restart your mac for changes to be reflected in your terminal.
There you go nestjs cli is now working globally 2nd screenshot.
I have just succeeded with
npx #nets/cli new project
when asked what manager to choose from npm / yarn / pnpm
made choice for pnpm
cd project
npm run start
Take care!
Must use sudo in comandline for linux, otherwise the command nest cannot be add to /usr/local/bin folder:
sudo npm install -g #nestjs/cli
You can try to use sudo
sudo yarn global add #nestjs/cli
I got the same issue.
I just uninstalled and reinstalled nextjs.
Finally, I can use next -v
I want to install a newest version of NodeJS on Ubuntu Zesty 17.04. But whether using apt-get or trying to download it from nodesource ppa, I always have the version 4.7.2.
Apt-get
sudo apt-get update
sudo apt-get install nodejs npm
Node PPA
curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
sudo apt-get update
apt-get install nodejs npm
Result
$> node -v
v4.7.2
How can I get the version 6.9 of NodeJS ?
I didn't succeed to install it via apt-get or nodesource ppa. However I solved the problem by installing Node manually by following these steps :
Remove the old version sudo apt-get remove --purge node
Download Node binaries from https://nodejs.org/en/
Extract the archive where you want tar -xzf <ARCHIVE>.tar.gz -C <YOUR_FOLDER>
Create a node symbolic link ln -sf <YOUR_FOLDER>/bin/node /usr/bin/node
Create a nodejs symbolic link ln -sf <YOUR_FOLDER>/bin/node /usr/bin/nodejs
result :
radouane#roufid:$ node -v
v6.10.2
I hope it helps !
Best way is to use n. It is a node module that helps you to update and switch between node versions easily.
npm install n --global
n list will list all node versions.
If you want to switch to new version 6.10.2 use command
n 6.10.2
To install the NodeJS any version
# you can replace number 6 with new version
curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
sudo apt install nodejs
node -v