Vagrant Node Version Not Updating in VM - npm

I am currently trying to do this:
https://github.com/workshopper/javascripting#run-the-workshop
When I type javascripting it gives me the error:
EEXIST: file already exists, mkdir '/home/vagrant/.config/workshopper'
From what I've found the EEXIST errors comes from the node version not being updated.
The terminal on my mac shows:
% node -v
v12.18.3
% npm -v
6.14.6
But the terminal inside my Vagrant VM shows:
% node -v
v8.9.4
% npm -v
5.6.0
I am assuming it is because /usr/local/bin is not in my $PATH but I'm not sure how to update that, or even if that is the problem. Been struggling with this for a while and haven't found anything online that fixes it.
How do I update node and npm inside the VM?
Thanks.
[Edit]
Just in the odd case someone has this problem in the future, here is how I managed to fix it.
Inside of the VM run:
nvm ls
check to make sure the default is the latest version (in my case it should have been v12.18.3). If it is not the latest, then use:
nvm alias default (latest version number)
If you don't restart your VM then it may not update the current version. In that case use:
nvm use (latest version number)
And then you should be good to go.
Hope this helps!

For me, it was because the node version on my computer was newer than the node version in vagrant. I updated node in vagrant and it worked.
nvm install <version>
nvm use <version>

Related

nvm use does not switch node versions

on a Windows 10 machine and using nvm4w I tried:
from the above image:
node --version to check the current version
nvm list to list installed versions
nvm use 8.8.1 so we switch from 6 to 8
nvm on to enable it
node --version to re-check the node version
what am I doing wrong?
I had to delete the folder located at C:\Program Files\nodejs:
And then run nvm use {version} again to repopulate this folder with the correct node version.
I suspect that nvm is having trouble deleting this folder due to permission issues.
So I found a workaround.
I renamed C:\Program Files\nodejs to C:\Program Files\nodejsx
and then running nvm use versionNumber works fine.
Seems like nvm cannot change it to a symlink and fails silently.
I was also facing the same issue.
I had node version 14.15.1 installed in my machine and had to use 12.16.1
I'm using Windows 10.
After installing 12.16.1 via nvm it was showing only this version in nvm list and it wasn't showing current version in use.
Even after node use 12.16.1 the node -v was still showing 14.15.1.
Steps to resolve this issue:
Uninstall Nodejs from control panel.
Install Nodejs 12.16.1 using nvm install 12.16.1
Install Nodejs 14.15.1 using nvm install 14.15.1 (or the version which got uninstalled)
Switch version using nvm use 12.16.1 (change the version number accordingly)
Result:
C:\>nvm list
14.15.1
* 12.16.1 (Currently using 64-bit executable)
12.3.1
C:\>node -v
v12.16.1
nvm works based on the fundamental idea of symlinks. When a user is trying to hit the command nvm install <node_version> the entered version of node is getting installed even if you have changed the C:\Program Files\nodejs to C:\Program Files\nodejsx.
If nvm fails to create the new folder C:\Program Files\nodejs it will fail silently and you won't be informed.
You must manually check for the existence of the path C:\Program Files\nodejs if it exits then delete the folder and change the node path in your environmental variables. This will help you to figure out the version of the npm command.
Your problem can be solved by reinstalling the nvm version with Administrator privileges or just by renaming the folder C:\Program Files\nodejs
You can find further information here: https://github.com/coreybutler/nvm-windows/issues/67
This happens to be the issue till date and deleting nodejs folder does not work.
Just run nvm install using cmd as administrator.
So even if you have downloaded nodejs from cmd without admin privilages, uninstall it and install again using cmd as admin.
This is what worked for me after trying almost every solution from github and stackoverflow.
For me the problem (on Linux) was that I had installed node with Homebrew, and it was preventing the use of nvm. Before nvm could set up the correct symlink, I had to
brew uninstall node
I first found out about this situation by running
which node
This told me that node was being symlinked from Homebrew at
/home/linuxbrew/.linuxbrew/bin/node
instead of, as we want, from nvm at
/home/john/.nvm/versions...
As soon as "which node" reported that it was using the node from nvm, things were resolved for me.
1) Install NVM from the link : https://github.com/coreybutler/nvm-windows/releases.
2) Copy the settings.txt from the "C:\Users\YOUR_USERNAME\AppData\Roaming\nvm". to "C:\Users\ YOUR_USERNAME"
3) Restart your system for the changes to reflect.
4) Open the console and type below command :
nvm list
5) To install the 6.9.3 version run the below command :
nvm install 6.9.3
6) After the installation is complete it will add the node version in the nvm. To check the same type command :
nvm list
7) To switch the command version type command below command :
nvm use 6.9.3
To verify the node version switch type the command “node –v”
8) Its will display the node version in use.
For more details please check the below link :
https://www.tutespace.com/2018/11/nvm-installation-on-windows.html
Let us know if you still face the same issue.
I had the same problem.
My solution is that i uninstalled nodejs via chocolatey (the way i installed it) and then nvm worked again.
After checking the nodejs folder in C:/Program Files i noticed that nvm probably works via creating a link/shortcut to the nvm folder where the different versions of nodejs are stored. That´s the way the "Path" and everything works.
I hope that helped.
I have tried to switch Node version using nvm but it is not reflecting so I deleted the folder inside c:/program files/nodejs
after deleting the folder follow the same steps to switch the npm version using nvm and it will switch the node version.
The steps I had to follow were:
Uninstall node if there was an installation outside of nvm
Ensure "C:\Program Files\nodejs" was deleted before installing nvm
Install nvm which still fails to install node but from the errors it seems that's because its ultimately pointing at urls that have been decomissioned
Use "nvm install NODE_VERSION" to install at least 2 versions of node which again fail as in 3)
Download the versions of node I tried to install and unzip the entire contents to their respective %appdata%/nvm/vNode_version folders
Use "nvm use NODE_VERSION" to switch between either version I've installed [but be careful... "npm -v" did not work until in visual studio until I closed and re-opened the program]
If anyone knows how to point nvm to the up to date urls, it'd be great to know. I suspect everything would work fine when running nvm from powershell run as administrator
Follow this step
1.delete node and npm in path
To Find Path
which node
output
/c/Users/balaji/AppData/Roaming/npm/node
which npm
output
/c/program files/node.js
2.To list out version
nvm list
3.set node
nvm use version
To know remote version
nvm list available
To know local version
nvm list
Yet another answer because none of the others helped me.
Setup
Windows 11
Multiple accounts
Non-default install and symlink directories
I installed nvm using different directories than the default because this is necessary to avoid:
Issues due to spaces in the path
Issues when using nvm on two different accounts on the same machine
Solution
This solution works for any number of accounts on the same machine.
Uninstall any nvm and nodejs you have.
Make sure no directory from them remains (in Program Files, Program Files (x86) and any other place you might have tried installing nvm/nodejs)
Reinstall nvm with:
An installation path that contains no spaces, and is not in any specific user's directory (e.g. C:\nvm)
A symlink path that contains no spaces, is not in any specific user's directory, and is not under nvm's directory (e.g. C:\nodejs)
Open your shell as administrator, install your desired node version(s) (e.g. nvm install lts) and activate one (e.g. nvm use 18)
Test that the version was activated correctly with nvm current and node --version
Every time you change your node version with nvm use or install a new one with nvm install, do it in an administrator shell
None of the above helped in my case.
I could see the symlink was created and correct but NVM4W would still not "use" the correct version.
The node version I had installed with NVM was not compatible with my version of Windows.
When you run "nvm ls" or "nvm current", it calls GetCurrentVersion() which runs "node -v" in the command line. If that output is anything other than the current version, such as the warning that you are running an incompatible OS, it will fail to indicate the currently selected version. It does so in a way that is not obvious why "nvm use x" did not work.
You can bypass the node OS check with an environment variable (node version >=14 as far as I could find):
How to set the NODE_SKIP_PLATFORM_CHECK environment variable to 1 which skips the version check
Though you may need to update Windows or use an earlier version of node if node doesn't function as expected.
With that set, "nvm use" functioned as expected.
I met this problem this morning. And I think the reason for the problem is that it's different between the nvm's settings and env configuration. I solved it the following way.
open the path of nvm installation.
open the setting.txt file and have a check with the path value.
open the environment variables Control panel in Windows.
check if it's the same between the value of NVM_SYMLINK in the system path and path in the setting.txt
change two configuration to same values.
Mine was caused by EMSDK. which I set on my .zshrc to load it automatically. removed the emsdk related lines, and the node was following nvm.
On Windows uninstalling Node.js at Control Panel > Programs > Uninstall a program, and letting nvm install the desired node versions also solves this issue.
In my case the things didn't work as described inside CI/CD service (TeamCity to be exact). I spent half a day, trying to find a solution and tried everything mentioned here and other similar questions. So, what worked:
Perform a clean install of nvm (removing older standalone versions of nodejs fist), as specified by multiple other answers. Install node versions only using nvm.
Make sure that process that is running your "nvm use" command has "Full Control" privilege to the root of nvm installation. So that it could delete the symbolic link "nodejs" folder when switching versions.
Change a policy on your server to allow that same account creating symbolic links:
This point was, somehow, not mentioned by anyone anywhere, so it took me very long time to figure this out.

npm install error `not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:`

I have installed Ubuntu Bash on Windows. I already have nodejs and npm on my windows machine at C:\Program Files\nodejs. In the bash shell in Windows, I am running a script which uses npm install command. The script is giving following error
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
Note: Before following the steps below, first try to restart your shell.
You can install Node.js and NPM with your Windows PowerShell as well, so if you've done that it won't work properly for your Subsystem. That means you have to install it twice (Powershell and Subsystem) or decide on one thing.
If the preceding text, has not helped you, this is how to solve the problem:
Remove your current installations
sudo apt-get --purge remove node
("sudo apt autoremove node" if console is asking for it)
sudo apt-get --purge remove nodejs
Install node the right way.
This is for version 14 (view current LTS version):
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
Then install build tools so you can install add-ons for npm later
sudo apt-get install -y build-essential
Now you can type in
npm -v
node -v
Same thing: nodejs -v
to check whether Node.js and NPM are installed correctly. If it shows nothing, restart the shell.
If it still shows the same error, restart the WSL/ PC or try with sudo npm -v
Here are two links that may also help you.
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
https://github.com/nodesource/distributions/blob/master/README.md#debinstall
Also, take a look at the Node Version Manager (NVM). With it, you can easily switch back and forth between versions.
The solution provided by phucanhapril on May 24, 2017 in this thread worked for me.
To summarise, edit ~/.profile and change your PATH to this:
PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"
(By default it does not include /usr/bin)
Then run:
source ~/.profile
I am not quite sure why npm doesn't work properly in the first place, or why /usr/bin isn't in PATH by default, but the solution worked for me.
I had the same problem to solve I installed "NVM" in my Subsystem
Follow these steps and see if it will solve for you:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile
nvm install 11.13.0
You can try sudo npm install it was a solution in my particular case.
Linux command for install nodejs and npm
sudo apt-get install nodejs
sudo apt-get install npm
Set path in linux
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
reference
https://github.com/microsoft/WSL/issues/3882
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
this is enough, if you still face the problem
node installation needs restart, close you ubuntu window and start again it will solve your problem :)
I had the same problem. This is what I did.
Step 1. Type node -v and npm -v commands in Windows PowerShell and check if node and npm are properly installed
Step 2. Add this to the ~/.zshrc or ~/.bashrc file
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Step 3. Type source ~/.zshrc and/or source ~/.bashrc
Step 4. Type node -v and npm -v commands in bash or zsh shells and the correct versions should now appear
On Visual Studio -> Tools -> Options -> Projects and Solutions -> Web Package Management -> make sure $(PATH) is above all the rest.
As long it is not located at the top of the list VS will try to use VS tools instead of npm.
You should also refer windows to the current npm version by following this screenshot, after try npm --version.
Changing npm path:
I had this issue in both Debian and Ubuntu (though in Ubuntu the nvm command did work) when I was running Windows 10 version 1703. Then when I upgraded to version 1903 the problem disappeared.
I had the same error and it may seem silly, but I fixed it by simply typing exit in the console and opening it again.
I received this error when I modified my "~/.bashrc" file to shorten up the bash directory.
At first I had:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\$'
fi
....But then could not run any node operation. I rolled it back and the error stopped happening.
After some troubleshooting, I was able to fix the error by adding ~ before the $ on PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\~$
I just read through many threads trying to do this. There is complete documentation for setting up node, nvm, and npm in wsl, here: https://learn.microsoft.com/en-us/windows/nodejs/setup-on-wsl2
If you already installed node and npm using the following commands,
sudo apt-get install nodejs
sudo apt-get install npm
NPM will not work. You must first uninstall them using:
sudo apt-get remove nodejs
sudo apt-get remove npm
Follow the guide to completely uninstalling here: How can I completely uninstall nodejs, npm and node in Ubuntu
Then reinstall from the windows guide referenced above.
The windows guide has many other useful resources.
The Tldr to install(from Microsoft Docs):
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install --lts
I had identical output to that in the question. It occurs because Ubuntu on WSL adds Windows paths to the bash shell, but of course the Windows executables do not work in bash.
I installed nvm, and from there installed node into bash. NVM works out all the paths so it works.

How do I change the version of yarn used?

I used Homebrew to install yarn. Running yarn -v shows that I currently use 0.23.2. I ran brew upgrade yarn to get the latest version, which is 0.24.6.
After Homebrew successfully upgrades yarn, I run yarn -v again, but the version is still 0.23.2. How can I change the version of yarn that I am running?
yarn policies set-version <version number>
Per https://github.com/yarnpkg/yarn/issues/7146#issuecomment-477809216
You can use homebrew and yarn formula URLs to install older versions of yarn, then brew switch between yarn versions as needed. Works perfectly! Credit to github user robertmorgan.
First off, if you already have a version installed, unlink it from brew running the brew unlink yarn command in your terminal.
Next, in a web browser, find the Pull Request that has been merged which contained the formula (version) of
Yarn
that you want to install.
View the files changed in that Pull Request - there should be one for Formula/yarn.rb.
Click the "View" button for the Formula/yarn.rb file to see the whole contents of the file for that commit.
Click the button to view the "Raw" version of that file. This will open a url which should start with
https://raw.githubusercontent.com/....
This is the URL that you will need for the next step - so copy the complete URL to your clipboard.
Back in your terminal window, use the command brew install followed by the URL that you've copied.
e.g. to install v1.6.0 of yarn it would be:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/fba7635ab69384ac980c635483a7af825bc06088/Formula/yarn.rb
You can then verify the versions available to Homebrew by running:
brew list --versions yarn, and switch between versions using brew switch yarn VERSION_NUMBER
Source: https://github.com/yarnpkg/yarn/issues/1882#issuecomment-421372892
I found an answer. It's not the prettiest, but since yarn always tell me what the most update-to-date version is, I can use npm to just install the latest version.
If the latest is 0.24.6
npm install --global yarn#.24.6
EDIT:
According to yarn's official documentation, the way to install/upgrade is:
brew install yarn
brew upgrade yarn
https://yarnpkg.com/en/docs/install#mac-stable
Your best bet would be to use a yarn version manager.
Install:
curl -fsSL https://raw.githubusercontent.com/tophat/yvm/master/scripts/install.sh | bash
Single usage:
yvm exec <version> <command>
Or to switch your currently running yarn version
yvm use <version>
yarn --version
UPDATE Dec 2021:
Sadly brew switch is deprecated in Homebrew 2.6.0 (December 2020)
$ brew switch
Error: Unknown command: switch
TLDR, to switch version:
brew unlink yarn
brew link yarn#<new_version>
Old solution:
Assuming that you have the other version installed, you can run
brew switch yarn <old_version>
To list the versions you have installed:
brew list --versions yarn
You can use
yarn set version <version>
For example, if you want the latest version, you can run
yarn set version latest
You can also set it to a specific number, for example,
yarn set version 1.22.1
You can view the full documentation at the official website.
Note 1: A bug stops you from switching from yarn 2 to yarn 1. There are solutions to this in this GitHub issue.
Note 2: I don't use brew, but this solution should still work.
Easily install and switch between any number of yarn versions.
https://github.com/tophat/yvm
Here's a way to do it with only curl and bash:
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.24.6 # or another version
This works whether you have yarn installed or not.
For updating version on macOS use below command:
$ brew upgrade yarn
Some of the above answers don't seem to work anymore. Here is how I was able to install a different version in April 2021:
brew unlink yarn#1.6.0 (If you already have a version installed)
brew extract --version 1.22.4 yarn homebrew/cask
brew install yarn#1.22.4
yarn -v

nvm problems on Mac OSX

When I successfully installed nvm on Mac, I also activated nvm source ~/.nvm/nvm.sh.
When I run commmand -v nvm, I also can output nvm.
However, when it comes to nvm install node, terminal alerts:
nvm needs curl or wget to proceed.
How to fix it?

npm module n emits errors

After installing n by command 'sudo npm install -g n',
I want list all node versions,but some errors come out, even though, n can work normally!
As bellow:
$ n list
/usr/bin/n: line 262: which: command not found
/usr/bin/n: line 262: which: command not found
0.0.1
0.0.2
0.0.3
0.0.4
I don't know why, there is no need to configure my bin foldeer.
I have solved it, after npm install which...
sudo npm install -g whitch
Try installing which
sudo apt-get install which
This is fixed in the current version of n.
Old versions of n used the which command which is not standard. Newer versions only use command -v which is a standard posix command.