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

Add "current" symlink to NVM_DIR #447

Closed
wants to merge 4 commits into from
Closed

Add "current" symlink to NVM_DIR #447

wants to merge 4 commits into from

Conversation

danielb2
Copy link
Contributor

Adresses #430

@@ -526,6 +526,7 @@ nvm() {
export NODE_PATH
export NVM_PATH="$NVM_DIR/$VERSION/lib/node"
export NVM_BIN="$NVM_DIR/$VERSION/bin"
rm -rf "$NVM_DIR/current" && ln -sf "$NVM_DIR/$VERSION" "$NVM_DIR/current"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using -f on ln, why rm first? Alternatively, if you've just rmd it, why -f?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -f doesn't actually force a new link (I tried). The -fon both rm and ln make sure there's no noise or warnings if they fail. I can change it to non-silent fail if that's preferred.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, that makes sense. This is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-r is not needed here though, and -f can be left out for ln if you remove the link first

@ljharb
Copy link
Member

ljharb commented Jun 27, 2014

Could you try to add a test? You should be able to write a fast test, that does something like mkdir v0.0.1 && nvm use 0.0.1 and then verify that the symlink exists, and that it maps to v0.0.1?

@danielb2
Copy link
Contributor Author

Sure

@danielb2
Copy link
Contributor Author

danielb2 commented Jul 5, 2014

OK, added test. But test seems to fail. Although test seems to fail on main master as well, so not sure what to do about that.

@ljharb
Copy link
Member

ljharb commented Jul 12, 2014

This looks great, but we need the test to fail on master and pass on your branch in order for it to be valid.

@danielb2
Copy link
Contributor Author

That makes no sense. The test passes when I run it locally. A bunch of other tests fail locally however.

@koenpunt
Copy link
Contributor

You should unload nvm (nvm unload) or set $NVM_DIR explicitly to the repo directory before running the tests.

@ljharb ljharb closed this in 8f66273 Jul 13, 2014
@jokeyrhyme
Copy link

I have a use case where I install NVM to /opt/nvm, owned by root, and load nvm.sh by regular (non-root) users. Node.JS versions and global NPM packages are installed by root, but regular users can use the executables for their own projects. I went this route to prevent having multiple copies of the same version of Node.JS (and save time having to compile the same version multiple times).

The change in this PR breaks NVM for my regular users, as they are now unable to select a Node.JS version for their current session. Users get the following error:

rm: cannot remove ‘/opt/nvm/current’: Permission denied

Any ideas?

@ljharb
Copy link
Member

ljharb commented Jul 17, 2014

NVM_DIR isn't meant to be shared. I think it would make more sense to give each user their own NVM_DIR, and hard link in (from a shared location) each of the node versions you want.

@danielb2
Copy link
Contributor Author

The failing rm -f shouldn't impact anything except the failure to create the symlink. Are you saying it's halting execution and not changing the version of node?

@jokeyrhyme
Copy link

Sorry, you're correct in that it isn't breaking anything in NVM. It does cause the script to exit with a non-zero exit code, which causes some of my other scripts to fail (e.g. Vagrant, Ansible, etc).

Node.JS's presence in distribution package managers is now much better than it was when I first resorted to using NVM, so I've switched to that where I can. In the remaining areas (e.g. Node.JS on ARM), I'll transition to per-user NVM_DIR with sym-links to globally installed versions.

@danielb2
Copy link
Contributor Author

This is what I'm seeing. Are you sure this is the cause of the non-zero exit code?

$ nvm use 0.10
rm: /Users/daniel/tmp/nvm/current: Permission denied
Now using node v0.10.29
[~/tmp/nvm]$ echo $?
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants