nvm icon indicating copy to clipboard operation
nvm copied to clipboard

adjust for symbolic links

Open aiqui opened this issue 5 years ago • 7 comments

Currently the nvm.sh script does not handle directories that are symbolic links. This is a common problem on servers that use symbolic links to persistent drives. For example, an admin might want to install nvm into /opt/local/node, but the real location (without the symlinks) is /files2/opt-local/node/nvm. This results in:

export NVM_DIR=/opt/local/node/nvm && . "$NVM_DIR/nvm.sh"
nvm is not compatible with the npm config "prefix" option: currently set to "/files2/opt-local/node/nvm/versions/node/v8.11.3"
Run `npm config delete prefix` or `nvm use --delete-prefix v8.11.3 --silent` to unset it.

Assuming the admin knows this issue and uses the real directory, there is no problem:

export NVM_DIR=/files2/opt-local/node/nvm && . "$NVM_DIR/nvm.sh"

The small change I am providing will get the real directory to avoid the problem with symbolic links.

I don't know if cd -P is available on all Linux systems, but I have tested in MacOS, RedHat, AWS AMI and Debian.

aiqui avatar Jan 08 '20 17:01 aiqui

Does this perhaps fix #617 and then also close #1385, and then perhaps address some of the issues in #855?

ljharb avatar Jan 08 '20 22:01 ljharb

The code looks good, but this is breaking existing unit tests for nvm_tree_contains_path.

ljharb avatar Jan 12 '20 21:01 ljharb

@aiqui any interest in completing this PR?

ljharb avatar Sep 17 '20 06:09 ljharb

I've started some more work on this in https://github.com/olivermg/nvm .

However, the current state does not yet fix the complaint of nvm whenever $HOME is being set to a path that contains a symlink. I'll see if I can find out some more and improve the situation.

olivermg avatar Sep 20 '20 19:09 olivermg

Hey @olivermg, want to check on latest master branch, my PR from the other day adjusted the prefix check to handle symlinks, so it never hits the nvm_tree_contains_path code anymore.

dylanarmstrong avatar Oct 14 '20 15:10 dylanarmstrong

(See also, #2146 and #2045)

ljharb avatar Oct 14 '20 23:10 ljharb

@aiqui @olivermg i'd love to finish this PR and get it landed; would either of you be interested in doing that? @olivermg, you can comment a link to your branch and I'll pull in the changes.

ljharb avatar Dec 05 '23 04:12 ljharb