I have installed some Node.js versions with the tool n. I have uninstalled all Node.js versions using:
sudo n prune
except the current (activated) version. If I try to unsinstall the current version:
sudo n rm 6.10.2
I get the following error.:
Error: cannot remove currently active version (node/6.10.2).
I can not figure out, how to set the systems (Arch Linux) default Node.js version, which is already installed and was used to install n.
If uninstall n using:
sudo npm uninstall -g n
it leaves the current version on my computer.
ls /usr/local/n/versions/node/
6.10.2/
Do I need to manually delete the folder: /usr/local/n/? Or, is there an option in n to uninstall it and all the Node.js versions installed by n, so that I get the setting before I installed n?
You need to manually remove Node versions installed by n and set the correct Node system version.
sudo n prune
sudo npm uninstall -g n
sudo rm -r /usr/local/n
sudo rm /usr/local/bin/node
See the following issues for n on GitHub:
Cant uninstall n and node #327
Simple command to switch back to the system installation of Node #486
There have been some changes in n, so I'll provide an updated and longer answer.
First some context. n installs by default to /usr/local. If that is also the location of the "system" install of node and npm then it is overwritten. The cache of previously downloaded versions is kept in /usr/local/n.
Removing cached node versions downloaded by n:
n prune removes all but the version matching the active version of node
since n v3.0.0, deleting the active version is allowed using n rm <version>
(but just manually deleting /usr/local/n is easy and removes the top folder too!)
Removing installed node and npm and npx et al:
since n v4.1.0, there is n uninstall. (You will need to reinstall the system node and npm to keep using them if they were installed to same location and overwritten.)
Uninstalling n itself: if you installed it with npm install n then you uninstall it with npm uninstall n. This does not affect the cached versions of node or the installed version of node, just n. (And there is a small catch-22 if just deleted npm by running n uninstall!)
I'm on mac OSX, so I'm not sure if this is relevant to your use case or not, but it may help.
It looks like n may run into issues if you remove the current version, so I suggest that you delete the folder: /usr/local/n/
Then try to uninstall 'n'. In my case, running npm uninstall -g n did not remove n. Instead, I needed to find the current installation of n by running: which n, then removing that folder from my system.
Then, I would suggest that you use NVM instead.
I've found that it's the easiest and most reliable solution that I've found to date.
More specifically, to address your question about how to access the system installation of node, I don't know what OS you are running, but I don't know that there is a system node version.
Typically, you have to manually install node. If there were a system node version, I would expect that it would become outdated very quickly, considering node, and other tools, typically iterate through changes fairly quickly.
I hope this works for you.
Run n-uninstall to uninstall n as well as the Node.js versions that were installed with it.
n-uninstall -y skips the confirmation prompt - use with caution.
Related
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
I am using Ubuntu Linux.
How can I check current nodejs version? I guess, I have 6 version, but I am not sure.
And is there way to change it, because I need 4 version. Can some one give step by step commands?
Open up the terminal and type node -v
To change your node version, I'd recommend installing nvm. Once installed, to switch versions it's as simple as
nvm use <version>
You can check your current NodeJS version by using command node -v.
And changing your version can be done by using node version manager.
The easiest way to do that is by running this $ npm install -g n now you can change your current NodeJS version using n (version)
e.g. n 4.0.0.
node -v
npm install -g n
n 4.0.0
You can check your version by using this code (node -v) in linux terminal and If you want to upgrade it to stable version you can use following codes one by one.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Just type npm version in your command line and it will display all the version details about node, npm, v8 engine etc.
To change your node version, I'd recommend installing nvm. Once installed, switch versions follow the instruction below;
nvm use <any specified version you prefer "example v16.0.0">
Example:
nvm alias default 16
This will enforce as the current default version.
On my Mac, I'd like to use Homebrew to install an earlier version of Node and NPM - I'm currently running Node/NPM 8.2.1/5.3.0, and I'd like to switch to 6.11.2/3.10.10, as listed in the documentation.
I ran
$ brew install node#6
$ brew unlink node
$ brew link node# --force
and while this appears to change my node version - $ node -v -> 6.11.2 - my version of NPM is still stuck at 5.3.0.
How can I switch NPM to this other version (and switch it back, if need be)?
Try to uninstall all node versions firstly: brew rm node, after that ensure that node -v and npm -v prints command not found.
After that install nvm or n to manage node versions. These version managers have one great advantage, they allow you to have a few node versions and easily switch between them.
nvm - Node Version Manager
n - Node version management
With nvm:
nvm install v6.11.2
Luckily there is a good way to do this if you are someone like myself who finds nvm to be overkill, especially if you only need one version for an app/api support (e.g. johnny-five). Instead of installing a node version manager, you can actually create a 2nd "node" version with another homebrew node.js install.
Start by installing the other version of node that you want to use, for instance node#4, and then unlink that version's symlinks (you can use any brew installed version).
$ brew install node#4 && brew unlink node#4
Once it's installed and unlinked, go to the folder /usr/local/bin, and add a custom symlink for the other version you want access:
$ cd /usr/local/bin
$ ln -s ../Cellar/node\#4/4.8.5/bin/node ./node4
Now you can use the command node for your previous version, and node4 for the node#4 version.
Of course we do not want to mix npm packages with the two versions, so let's fix that by making a new npm directory for the node#4 version:
$ mkdir ~/.npm4
$ npm config set prefix ~/.npm4
Now you are ready to install global packages for the second version! Each time you want to switch versions you can simply swap the prefix, and since we are looking for a simple process this probably won't happen too often.
Of course you may want something that does not require the need to be proactive when switching versions, and while you can always install a separate version of npm somewhere and symlink it the same way you did the node version, that may become confusing over time when it comes to upgrading npm.
A few other options:
script the prefix command
add the prefix command and/or script in package.json
use a specific bash terminal profile that runs the prefix command on start
So there are few various options, but I will leave that all up to you..
I attempted an upgrade of Node using brew, but after the upgrade I am left with two versions. How can I get rid of the old one?
When I run brew upgrade node It tells me that 0.12.7 is already installed.
However if I run node -v
I get the version 0.10.26. It appears that I now have two versions installed.
How can I remove the oldest version?
One option is to delete your node binary folder which will contain those two files:
sudo rm -rf /usr/local/lib/node
And then run install again:
brew install node
Be sure to backup your folder PRIOR to doing this in the case it freaks out.
Also - from personal experience, homebrew creates more problems that it solves. Just use the Node.js install script on their website.
I'm trying to update Node.js on Ubuntu serever 14.04 using n.
n upgrades but the version is still the same:
root#0e2dbaa3db85:/home# node -v
v0.10.25
root#0e2dbaa3db85:/home# n 0.10.33
install : node-v0.10.33
mkdir : /usr/local/n/versions/node/0.10.33
fetch : https://nodejs.org/dist/v0.10.33/node-v0.10.33-linux-x64.tar.gz
installed : v0.10.33
root#0e2dbaa3db85:/home# node -v
v0.10.25
Do I have to tell n which version to use as default?
I've tried n latest, it installs 0.12.0 but node -v outputs 0.10.25 again.
What should I do?
On occasion the n package won't install the links for node, and the selection won't allow you to select any version installed by n.
When that happens, you need to install an "n" version of node so the selector will allow you to choose.
Here is what I had to do.
Use n to install a node version.
# n stable
install : node-v5.10.1
mkdir : /usr/local/n/versions/node/5.10.1
fetch : https://nodejs.org/dist/v5.10.1/node-v5.10.1-linux-x64.tar.gz
######################################################################## 100.0%
installed : v0.10.42
Select the node version from the install directory
In this case it is located at:
/usr/local/n/versions/node/5.10.1/bin/node
Replace existing node link with new node version
cd /bin
mv node node_old
ln -s /usr/local/n/versions/node/5.10.1/bin/node
At this point node should work, and n should allow you to select version.
Resolved by nvm.
I faced the same issue with you. I could not change node version with n because I installed nvm and used nvm to manage node versions before.
I resolved the issue by execute nvm command. For example: nvm install 11.8.0 then check node version node -v. Tada it works.
n 0.10.33 will install that version of node, but you still haven't selected it. After installing, simply execute n and pick the version you want to use.
n latest will install or activate the latest version of node. Run it twice to use node 0.12.0
Documentation.
I faced same issue, where I select a different version or even download a new version with n and it still shows the initial installation before I started using n. This worked for me:
Unlink
sudo unlink /usr/bin/node
Run n again to choose the node version.
After this two steps it worked
From what I can read from the n readme, you need to call n <version> to install, and then run n with no arguments, so a version picker will be shown:
Type n to prompt selection of an installed node. Use the up / down arrow to navigate, and press enter or the right arrow to select, or ^C to cancel:
(...)
Commands:
n <version> Install node <version>
However, if you run n latest, it will install or activate the latest version:
n latest Install or activate the latest node release
Try to set the simbolic link to node to the npm global folder.
sudo unlink /usr/bin/node
sudo ln -rs PATHTO/.npm-global/node/bin/nodee node
in my case, my path to npm-global dir was on my home. So the full path was /home/rafael/.npm-global/node/bin/node
After this, check if is allrigth:
node -v //return current node version
n stable //install the stable current version
node -v //will return the new version installed
n 8 //install the version 8 for test
node -v //will return the 8 version
Enjoy