Can Chocolatey recognize a manual nodejs installation? - node.js

Running command node -v gives the following value: v0.10.33. I know that Node.js currently is at version 0.12. Nevertheless, when running a choco update nodejs, the prompt says "Nothing to update". The same occurs with npm after a "choco update npm".
I have installed Node.js from the install package on their website nodejs.org.
A time after that I have also installed Chocolatey and have come to use the tool every now and then for package installations.
Is it possible to have Chocolatey recognize the existing Node.js installation and pick a choco update from there?
I would like to also be able to pick up the npm update from Chocolatey the same way as well.
I do not have the latest Chocolatey.
> choco list --local-only nodejs
Opciรณn desconocida: '--local-only'
nodejs.commandline 0.12.2
npm 1.4.9.20150213
EthanBrown.DevTools.Web 0.3.1
ghost 0.5.5.1
io.js 1.7.1
livestreamer-twitch-gui 0.7.1
nodejs 0.12.2
nodejs.install 0.12.2
node-webkit-0.9.2 0.9.2
node-webkit 0.6.2
Brackets.Theseus 0.2.8
Yeoman 1.1.2
After upgrading Chocolatey to v0.9.9.4
> choco list --local-only
Chocolatey v0.9.9.4 [nl] 0 packages installed.
I updated Node.js using npm.
> node -v
v0.12.2
However, after reinstalling Node.js at version 0.10.33,
> choco install nodejs -version 0.10.33
I cannot use npm:
Cannot find file at 'npm.cmd' (C:\ProgramData\chocolatey\lib\npm\tools\npm.cmd). This usually indicates a missing or moved file.
I'll leave it for now until I troubleshoot.

Another option, assuming that you already have Node.js installed via the MSI would be to run:
choco install nodejs -version 0.12.2 -y -n
The -n parameter, as documented here:
https://github.com/chocolatey/choco/wiki/CommandsInstall#options-and-switches
Skips the PowerShell script associated with the Chocolatey package. This essentially adds the package version into the Chocolatey repository, but it doesn't run the associated installation script.
This is what I "think" you are after.
NOTE: Not all packages have chocolateyinstall.ps1 files, and instead rely on the default installation behaviour of Chocolatey, i.e. creating shims for contained EXE files, etc. The skippowershell flag will not, to the best of my knowledge, stop this from happening.

Chocolatey cannot currently detect and incorporate already installed applications into its own library. Now, if you installed the Node.js MSI manually and then used Chocolatey to install the same or newer version, things might just work. The MSI system, while arcane, is pretty robust and most newer MSIs will subsume older ones.
Can you run the Chocolatey command to show us exactly which Node.js you have installed?
PS> choco list --local-only nodejs
Chocolatey v0.9.9.2
nodejs 0.10.33
nodejs.install 0.10.33
2 packages installed.
I have the same version installed. I just ran an update. I snipped the logs, but you can see that it updates.
PS> choco upgrade nodejs
Chocolatey v0.9.9.2
nodejs.install v0.12.2
nodejs v0.12.2
Chocolatey upgraded 2/2 package(s). 0 package(s) failed.
And Node.js is up-to-date.
PS> node -v
v0.12.2
And the application in the Programs and Features applet of the Control Panel is also updated. So, the Node.js MSI does the right thing here.
I think we need to see some more literal command output from your system to be sure you have all the right versions installed.

Related

Upgrading to a specific node js version

I am trying to upgrade my node to version 14.17.1 by running:
npm install -g node#14.17.1
It succeeds apparently, but when I run node -v, I still get the old version.
Is there an extra step I should take, or am I doing this wrong?
It is good to use a excellent and proven source. Visit official nodejs.org website and go to:
Other Downloads
Previous Releases - link
Choose and Install version whatever You want, on Operating System You
actually using. Good Luck ;-)
Or install and use nvm
To download, compile, and install the latest release of node, do this:
nvm install node # "node" is an alias for the latest version
To install a specific version of node:
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc

Unable to downgrade Node to specific version

I am building a sample application in which I need to use Node Version v9.11.2 and npm 4.0.0. Currently I have Node Version v16.4.0 installed on my system. I tried to install the specific version by uninstalling the latest version and installing version 9.11.2 from official website
Problem: The problem is I can uninstall the latest version without any problem but when I try to install older version(9.11.2) the command gets opened and it does nothing. I also tried to install the older version using cli commands ie. npm install -g node#9.11.2, it installs the version but on checking the version using node -v, it still shows the latest version(16.4.0)
Below are the screenshots for better understanding
Installed version 9.11.2 but showing 16.4.0
Any Solution please ?
Is using docker a possibility? If so you can simply get a docker image of the required version and use if from there.
Another way is to use NVM which is a really useful tool to manage nodejs versions. I'm including their github repo for your convenience:
https://github.com/nvm-sh/nvm
A good option is to use NVM: https://github.com/coreybutler/nvm-windows (Windows) or https://github.com/nvm-sh/nvm (unix, macOS). With NVM you can enable different versions of node on the same machine and switch from one to another, usually it takes care of managing the installed packages and adding them to its own management system.

Can I upgrade Node.js using command line in Windows?

Is it possible to update node using command line/PowerShell in windows 10?
Surely, I can download the latest version from the official site and install, but, I'm hoping for a way to do it from cmd.
Right now, I've npm and yarn installed on my system if that helps.
Perhaps nvm-windows is what you are looking for.
After installing this program on your computer, you will be able to use nvm command (Node Version Manager) in windows command line and manipulate with node.js versions.
Commands that you probably need are:
nvm install latest: To install the latest stable version
nvm list available: Show a list of versions available for download.
nvm use <version>: Switch to use the specified version.
More information here
Since you have npm you can use this command in powershell:
npm install npm#latest -g
If you want documentation to refer to you can use:
npmjs documentation

Difference between NPM and NVM

I know npm is the package manager and nvm is the node version manager. I am currently trying to auto-install my development and production environment using Bash and forgot how I started out and in what order. After installing npm, I found our nvm was not installed.
Do I still need to install nvm? If so, what is the benefit?
nvm (Node Version Manager) is a tool that allows you to download and install Node.js. Check if you have it installed via nvm --version.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | bash
npm (Node Package Manager) is a tool that allows you to install javascript packages. Check if you have it installed via npm --version.
npm comes with Node.js so if you have node installed (node --version) you most likely have npm installed as well.
You don't need nvm unless you want to keep multiple versions of Node.js installed on your system or if you'd like to upgrade your version.
nvm as you said is an "active" nodejs version manager. You can have multiple versions of node on the same machine and switch by doing "nvm use version". npm respects nvm if it is present on the machine, meaning if you have 0.12.7 active and do npm install -g uuid, it will install it globally under 0.12.7 but if you switch to 4.0.0, uuid will no longer be globally available.
In any case you do not necessarily need nvm to install packages.
I see an analogy with Python for all the Python users out there.
nvm manages different versions of node. And node contains npm (package manager).
pyenv manages different versions of python. And python contains pip (package manager).

How to change to an older version of Node.js

I am running Node.js version v0.5.9-pre on Ubuntu 10.10.
I would like to be using version v0.5.0-pre.
How do I roll back to the older version of node?
*NIX (Linux, OS X, ...)
Use n, an extremely simple Node version manager that can be installed via npm.
Say you want Node.js v0.10.x to build Atom.
npm install -g n # Install n globally
n 0.10.33 # Install and use v0.10.33
Usage:
n # Output versions installed
n latest # Install or activate the latest node release
n stable # Install or activate the latest stable node release
n <version> # Install node <version>
n use <version> [args ...] # Execute node <version> with [args ...]
n bin <version> # Output bin path for <version>
n rm <version ...> # Remove the given version(s)
n --latest # Output the latest node version available
n --stable # Output the latest stable node version available
n ls # Output the versions of node available
Windows
Use nvm-windows, it's like nvm but for Windows. Download and run the installer, then:
nvm install v0.10.33 # Install v0.10.33
nvm use v0.10.33 # Use v0.10.33
Usage:
nvm install [version] # Download and install [version]
nvm uninstall [version] # Uninstall [version]
nvm use [version] # Switch to use [version]
nvm list # List installed versions
One way is to use NVM, the Node Version Manager.
Use following command to get nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
You can find it at https://github.com/creationix/nvm
It allows you to easily install and manage multiple versions of node. Here's a snippet from the help:
Usage:
nvm install <version> Download and install a <version>
nvm use <version> Modify PATH to use <version>
nvm ls List versions (installed versions are blue)
Update: Updated the answer because previous one was not relevant.
Follow below steps to update your node version.
1. Install nvm For this run below command in your terminal
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Note: If above command did not work for you, you can choose another option to install it. I have added an answer for this here
2. Install specific node version using nvm
For this run
Replace 12.14.1 with your node version
nvm install 12.14.1
Note: If you are getting error of NVM not recognised then run below command and then run above again
source ~/.nvm/nvm.sh
3. Make the installed version default
Note: Replace 12.14.1 with your installed version.
nvm alias default 12.14.1
and
nvm use 12.14.1
4. Check node version
node -v
And that's it.
Extra
To check list of installed node versions -- run below command
nvm ls
Why use any extension when you can do this without extension :)
Install specific version of node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Specific version : sudo n 4.4.4 instead of sudo n stable
With package.json - The Maintainable and Portable Way ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰
Lets each project specify its own version
You can add node as a dependency in package.json and control which version is used for a particular project. Upon executing a package.json "script", npm (and yarn) will use that version to run the script instead of the globally installed Node.js.
The node package accomplishes this by downloading a node binary for your local system and puts it into the node_modules/.bin directory.
You can also do this with the npm (or yarn) packages but you'll need to set your PATH up specifically or use something like npx that handles it for you.
Ubuntu - The Official Way (manually) ๐Ÿ˜ต
If you're on node 12 and want to downgrade to node 10, just remove node and follow the instructions for the desired version:
# Remove the version that is currently installed
sudo apt remove -y nodejs
# Setup sources for the version you want
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
# (Re-)Install Node
sudo apt-get install -y nodejs
Windows - The Official Way (manually) ๐Ÿ˜ต
I found myself wanting to downgrade to LTS on Windows from the bleeding edge. If you're not using a package manager like Chocolatey or a node version manager like nvm or n, just download the .msi for the version you want and install it. You might want to remove the currently installed version via "Add or remove programs" tool in Windows.
Windows Package Manager - winget ๐ŸŽ‰๐ŸŽ‰
The Open Source Windows Package Manager Way
winget install -e --id OpenJS.Nodejs -v 14.9.0
Chocolatey - The Independent Package Manager Way ๐ŸŽ‰
Chocolatey is good for keeping installations up to date easily and it is a common way to install Node.js on Windows. I had to remove the bleeding edge version before installing the LTS version:
choco uninstall nodejs
choco install nodejs-lts
Node Version Manager - The "Screw it, I'll do it myself!" Way ๐Ÿ˜ข๐Ÿ˜ข๐Ÿ˜ข๐Ÿ˜ญ๐Ÿ˜ญ๐Ÿ˜ญ๐Ÿ˜ญ๐Ÿ˜ญ
While not very portable or easily maintainable, some developers like manually switching which global version of node is active at any given point in time and think the official ways of doing this are too slow. There are two popular Npm packages that provide helpful CLI interfaces for selecting (and automatically installing) whichever version you want for your system: nvm and n. Using either is beyond the scope of this answer.
I highly recommend staying away from this option. Even though it's popular, it's an anti-pattern that is sure to cause headaches in the future. Sure, .nvmrc exists, but this is reinventing something that's already a part of Npm. Just npm i node the version you want.
Windows
Downgrade Node with Chocolately
Install Chocolatey. Then run:
choco install nodejs.install -version 6.3.0
Chocolatey has lots of Node versions available.
Downgrade NPM
npm install -g npm#3.10.3
the easiest way i have found is to just use the nodejs.org site:
go to https://nodejs.org/en/download/releases/
find version you want and click download
on mac click the .pkg executable and follow the installation instructions (not sure what the correct executable is for windows)
be happy now that you are on the version of node you wanted
nvmw is no longer maintained, but I found another source that seems to be up to date (as of 1/4/17).
nvm-windows
It works. Allowed me to downgrade to 6.3.1
You need to install NVM for this.
For Mac
Edit .bash_profile using the below command.
nano .bash_profile
And add the following lines to .bash_profile
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
Save it. Exit the terminal and check the magic.
Then install the required version using the below command.
nvm install v14.18.0
If you want to check the installed node versions on your system. Use the below command.
nvm ls
If you want to use the specific version from the installed node versions. Use below command
nvm use 12.14.4
Another good library for managing multiple versions of Node is N: https://github.com/visionmedia/n
On windows 7 I used the general 'Uninstall Node.js' (just started typing in the search bottom left ,main menu field) followed by clicking the link to the older version which complies with the project, for instance:
Windows 64-bit Installer: https://nodejs.org/dist/v4.4.6/node-v4.4.6-x64.msi
I had node version 6.4.0 .
As i am need of the older version 6.3.0 , i just installed the 6.3.0 version again in my system. node version downgraded automatically.
So, to downgrade the node version ,
Just install the older version of node js . It will get downgraded automatically from the higher version.
I tried in osx . It works like a charm .
Now the v0.5.0-pre has reached end of life. We can use npx to use any stable older version of node. E.g. the earliest stable version is 4.9.0.
npx -p node#4.9.0 -- node -v
run this:
rm -rf node_modules && npm cache clear && npm install
Node will install from whatever is cached. So if you clear everything out first, then NPM use 0.10.xx, it will revert properly.
Easiest way i found -
Uninstall current version
Download the appropriate .msi installer (x64 or x86) for the desired version from https://nodejs.org/download/release/
Use following commnad with your version number
nvm install v8.9
nvm alias default v8.9
nvm use v8.9
For some reason Brew installs node 5 into a separate directory called node5.
The steps I took to get back to version 5 were: (You will need to look up standard brew installation/uninstallation, but otherwise this process is more straightforward than it looks.)
Install node5 using Brew standard installation, BUT don't brew link, yet.
Uninstall all other versions of node using brew unlink node and brew uninstall node. You might need to use --force to remove one of the versions.
Find the cellar folder on your computer
Delete the node folder in the cellar.
Rename the node5 folder to node.
Then, brew link node
You should be all set with node 5.
If you are like, you already install node version you want but can't seem to switch to it, try this:
nvm use --delete-prefix <version>. npm shows the lates version installed but can't switch to it. If so, this is the output you will see:
You need to run "nvm install v16.2.0
Then run:nvm install <type the version you wish to use here>Your output should look like this:
Downloading and installing node v16.2.0... Downloading https://nodejs.org/dist/v16.2.0/node-v16.2.0-linux-x64.tar.xz... ####################################################################### 100.0% Computing checksum with sha256sum Checksums matched! Now using node v16.2.0 (npm v7.13.0) Creating default alias: default -> v16.2.0
You are done! You can see the latest version by running:
node -v
if you want to go to the LTS version of node which is the stable one from the latest/current version simply run this in your directory.
npm i node
this will install the LTS version of node in your directory.
I faced a lot of issue with this and the only solution that worked for me is :
source ~/.nvm/nvm.sh
nvm isntall node_version_you_want
nvm use node_version_you_want
nvm install 0.5.0 #install previous version of choice
nvm alias default 0.5.0 #set it to default
nvm use default #use the new default as active version globally.
Without the last, the active version doesn't change to the new default. So, when you open a new terminal or restart server, the old default version remains active.
follow the steps if u already install curl its work for me
sudo snap remove curl
sudo apt install curl
nvm install 12.2.0
As i can see this was asked a long time ago, but maybe it can be helpful for someone else.
I can recommend this utility (NVS - Node Version Switcher) to someone who is searching for a way to switching between different versions of NodeJS:
https://github.com/jasongin/nvs
The Easiest way I find to install node.js with a specific version:
First uninstall your node.js
Go to, https://nodejs.org/en/download/releases/ and find your desired version.
Select your version and click on the download button.
Download .msi file

Resources