Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to uninstall n? #169

Closed
kamikat opened this issue Mar 28, 2014 · 27 comments
Closed

How to uninstall n? #169

kamikat opened this issue Mar 28, 2014 · 27 comments

Comments

@kamikat
Copy link

kamikat commented Mar 28, 2014

I'm wondering how to clean up my /usr/local directory after use n to switch between versions?

@yorkie
Copy link
Contributor

yorkie commented Mar 29, 2014

in /usr/local/n/versions, u could see your installed nodes. :p

@kamikat
Copy link
Author

kamikat commented Mar 29, 2014

Yes, but LICENSE README.md and ChangeLog appears in /usr/local/ as a result of cp -fR $dir/* $N_PREFIX.

The point is that no cleanup is done before switch to new version of node binary.

@yorkie
Copy link
Contributor

yorkie commented Mar 29, 2014

Oh, those files may be transferred there in once incorrect installation, just removed them and run sudo npm uninstall -g n. :)

@sonewman
Copy link

sonewman commented May 3, 2014

$ cd /usr/local/bin/n && sudo make uninstall

or just

$ sudo rm -rf /usr/local/bin/n

@kamikat
Copy link
Author

kamikat commented May 4, 2014

@sonewman the script will only removes n script but has nodejs remained. Not a full uninstall (I means, revert any changes n made to the root filesystem).

Or, the problem should be how to remove the node installed by n

@sonewman
Copy link

sonewman commented May 4, 2014

hmm, so you mean to set it back to the state that it was in before, i.e. the version of node originally installed? because to remove the node binary would be as simple as $ sudo rm /usr/local/bin/node but this would not set it back to a previous version you may have had install before using n

@tjwebb
Copy link
Collaborator

tjwebb commented May 20, 2014

Or, the problem should be how to remove the node installed by n

n rm <version>

See n help for more info

@tjwebb tjwebb closed this as completed May 26, 2014
@bennybennet
Copy link

Error: cannot remove currently active version (node/6.2.2)

@qw3rtman
Copy link
Collaborator

@bennybennet, are you trying to remove n or just a specific Node version installed by n?

@bennybennet
Copy link

tried to remove n but wanted to remove all node versions before.

@qw3rtman
Copy link
Collaborator

qw3rtman commented Jul 27, 2016

@bennybennet, you should just be able to npm rm -g n (uninstall n via npm) and then rm -rf /usr/local/n (where n stores binaries). The version you were last using will remain (at /usr/local/bin/node) along with npm (at /usr/local/lib/node_modules/npm/bin/npm).

@vergenzt
Copy link

I know this is an older issue, but I thought it worth commenting: If you installed via the method mentioned in the docs,

Additionally, consider third-party installer n-install, which allows installation directly from GitHub; for instance,

curl -L https://git.io/n-install | bash

sets both PREFIX and N_PREFIX to $HOME/n, installs n to $HOME/n/bin, modifies the initialization files of supported shells to export N_PREFIX and add $HOME/n/bin to the PATH, and installs the latest stable node version.

As a result, both n itself and all node versions it manages are hosted inside a single, optionally configurable directory, which you can later remove with the included n-uninstall script. n-update updates n itself to the latest version. See the n-install repo for more details.

then all you have to do is invoke ~/n/n-uninstall. :)

I had forgotten I used this method to install n and happened to find that script as I was manually cleaning things up. Thought I'd pass along the reminder.

@earthbound19
Copy link

At this writing I find the uninstall script at ~/n/bin/n-uninstall.

@trusktr
Copy link

trusktr commented Feb 10, 2018

~/n/n-uninstall

That's not official. n should include something like this, to make it clear exactly how to remove n and all versions installed by n, leaving only (for example) the node installed by Ubuntu's apt-get.

Basically, if I run

sudo apt-get install nodejs
sudo npm i -g n
sudo n 8

then, I simply want to go back to the state I had before as if I had ran only

sudo apt-get install nodejs

. So, if I intuitively try to do that like this:

sudo apt-get install nodejs
sudo npm i -g n
sudo n 8 # it installed 8.9.4
sudo n rm 8.9.4
 Error: cannot remove currently active version (node/8.9.4)

So (officially) we're stuck. Then, eventually, we might find something (unofficial) like ~/n/n-uninstall by stumbling here, which just doesn't seem right. The point of n is to manage versions, so being able to uninstall all versions should obviously be part of.... managing versions.

Furthermore, I didn't install n with n-install, so, now I have to go read a long bash script to make sure I can clean up?

This should just be built into n.

@trusktr
Copy link

trusktr commented Feb 10, 2018

Seriously, this sort of thing is annoying. It's like forgetting to write destructors and leaking memory in C++ classes. (no offense, I'm just annoyed that I have to go do it all manually, which negates the utility of the tool that I was hoping would save me time).

I know the solution might be easy (perhaps something like what @qw3rtman suggested above), but the thing is, it takes time to figure out what the solution is, even if it's a one-liner.

Good package managers (which n is) always have a way to uninstall everything installed, especially if the things to uninstall are not system-level packages (which node isn't).

@ryanmtaylor
Copy link

why not have "system" as a choice for nodes within n?

@mesqueeb
Copy link
Contributor

I came to a thread hoping to find the solution:
How to how to remove n and all versions installed by n?

Does anyone know the correct way?

@shadowspawn
Copy link
Collaborator

shadowspawn commented Sep 19, 2018

To be sure how to remove n we would need to know: How did you install n? Have you set the N_PREFIX environment variable to change the default install location n uses for installing node?

And some answers for the most common situations:

  1. If you installed n using
sudo npm install --global n

then you uninstall it using

sudo npm uninstall --global n
  1. If N_PREFIX is not set then n installs to usr/local by default and stores the downloaded versions in /usr/local/n/versions. To remove all the downloaded versions and the directory you can use:
sudo rm -rf /usr/local/n
  1. If N_PREFIX is set, then delete the "${N_PREFIX}/n" directory. And if you are not storing anything else in the N_PREFIX directory, you can delete the whole directory to delete both the downloaded versions and the installed current version of node.

To see if N_PREFIX is set you can run:

echo "N_PREFIX is: ${N_PREFIX}"

@shadowspawn
Copy link
Collaborator

shadowspawn commented Mar 27, 2019

I have opened a new issue #540 with some research and ideas about what we might do in future. Subscribe to that issue for updates and/or give it a 👍

Thank you for your contributions.

@shadowspawn
Copy link
Collaborator

shadowspawn commented May 13, 2019

n uninstall has been added in v4.1.0.

  • deletes node and npm from the install destination (N_PREFIX or /usr/local)
  • does not affect the cached downloaded versions
  • does not delete n itself

@NikitaKA
Copy link

NikitaKA commented Jul 10, 2019

I'm trying to uninstall n, but:

If I try n uninstall I get:

Error: invalid version uninstall

If I try npm r -g n:

up to date in 0.089s

If I try npm i -g n:

npm ERR! Cannot read property 'resolve' of undefined

And I didn't find n in npm -g list | grep n...

What am I doing wrong?

@shadowspawn
Copy link
Collaborator

@NikitaKA

Do you remember how you installed n? (Using npm? Using n-install? Using brew?)

What does this show?

command -v n

@NikitaKA
Copy link

NikitaKA commented Jul 12, 2019

I'm using Windows 10 Linux Subsystem (if that matters), n is installed via npm (95% sure).

command -v n:

/usr/bin/n

Node: 10.16.0
NPM: 6.9.0

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jul 12, 2019

(Edited after realising why install location different than I expected.)

The three things to delete are the n package, the n command (usually a link into the package), and the cache folder. Not sure why npm is not listing n but no matter, some more questions so I can hopefully give you some accurate instructions.

What do these show:

ls -l /usr/bin/n
ls -d /usr/local/n
echo $N_PREFIX

@NikitaKA
Copy link

ls -l /usr/bin/n
ls: cannot access '/usr/bin/n': No such file or directory

ls -d /usr/local/n
/usr/local/n

echo $N_PREFIX
(empty)

Thank you for help!

@shadowspawn
Copy link
Collaborator

Ok, manual cleanup for your setup, all that is left is the cache:

sudo rm -rf /usr/local/n

@NikitaKA
Copy link

I did that, but n was still in the system: /usr/local/bin/n
So I rm -rf it too. Now everything is fine. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests