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

nvm alias default not working as expected #3354

Closed
attisimon opened this issue May 16, 2024 · 11 comments
Closed

nvm alias default not working as expected #3354

attisimon opened this issue May 16, 2024 · 11 comments

Comments

@attisimon
Copy link

Operating system and version:

openSUSE Tumbleweed 20240514 (KDE, Wayland)

nvm debug output:

nvm --version: v0.39.7
$SHELL: /bin/bash
$SHLVL: 1
whoami: 'attila'
${HOME}: /home/attila
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${NVM_DIR}/versions/node/v16.20.2/bin:${HOME}/.local/bin:${HOME}/bin:/usr/local/bin:/usr/bin:/bin:/snap/bin:${HOME}/.config/composer/vendor/bin:${HOME}/.config/composer/vendor/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 5.2.26(1)-release (x86_64-suse-linux)'
uname -a: 'Linux 6.8.9-1-default #1 SMP PREEMPT_DYNAMIC Fri May 10 08:51:14 UTC 2024 (d3445e0) x86_64 x86_64 x86_64 GNU/Linux'
checksum binary: 'sha256sum'
OS version: Welcome to openSUSE Tumbleweed 20240514 - Kernel  ().
awk: /usr/bin/awk, GNU Awk 5.3.0, API 4.0, PMA Avon 8-g1, (GNU MPFR 4.2.1, GNU MP 6.3.0)
curl: /usr/bin/curl, curl 8.7.1 (x86_64-suse-linux-gnu) libcurl/8.7.1 OpenSSL/3.1.4 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libpsl/0.21.5 libssh/0.10.6/openssl/zlib nghttp2/1.61.0 OpenLDAP/2.6.6
wget: /usr/bin/wget, GNU Wget 1.24.5 built on linux-gnu.
git: /usr/bin/git, git version 2.45.0
grep: /usr/bin/grep (grep --color=auto), grep (GNU grep) 3.11
sed: /usr/bin/sed, sed (GNU sed) 4.9
cut: /usr/bin/cut, cut (GNU coreutils) 9.5
basename: /usr/bin/basename, basename (GNU coreutils) 9.5
rm: /usr/bin/rm, rm (GNU coreutils) 9.5
mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 9.5
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.9.0
nvm current: v16.20.2
which node: ${NVM_DIR}/versions/node/v16.20.2/bin/node
which iojs: which: no iojs in (${NVM_DIR}/versions/node/v16.20.2/bin:${HOME}/.local/bin:${HOME}/bin:/usr/local/bin:/usr/bin:/bin:/snap/bin:${HOME}/.config/composer/vendor/bin:${HOME}/.config/composer/vendor/bin)
which npm: ${NVM_DIR}/versions/node/v16.20.2/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v16.20.2
npm root -g: ${NVM_DIR}/versions/node/v16.20.2/lib/node_modules

nvm ls output:

       v14.21.3
->     v16.20.2
       v18.20.2
       v20.13.1
default -> lts/hydrogen (-> v18.20.2)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v20.13.1) (default)
stable -> 20.13 (-> v20.13.1) (default)
lts/* -> lts/iron (-> v20.13.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3
lts/gallium -> v16.20.2
lts/hydrogen -> v18.20.2
lts/iron -> v20.13.1

How did you install nvm?

script in readme:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

What steps did you perform?

  • installed 16
  • installed 18
  • installed 20
  • set alias default to 18, later on to lts/hydrogen
  • later installed 14 also

What happened?

Every new shell defaults to 16 instead of 18, I have to manually set the default with nvm use default

What did you expect to happen?

The default version to load by default :) in every new shell.

Is there anything in any of your profile files that modifies the PATH?

.bashrc:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
.
@ljharb
Copy link
Member

ljharb commented May 16, 2024

In the dir you're opening the shell, is there a .nvmrc file?

@attisimon
Copy link
Author

There is no .nvmrc file, this happens in any folder.
Or should I say it was happening, after a reboot everything seems to be happening as expected, any new shell has the default as default, 18 in my case.

@ljharb
Copy link
Member

ljharb commented May 17, 2024

Weird, please reopen if it happens again.

@attisimon
Copy link
Author

Just a note, this happened again, when having version 16 as default and setting 18 as the new default. Last time I thought there was an update that needed a system restart, but this time there was no update. However, the problem went away again with a restart.

The steps I took this time was:
0. I had version 16 set as default, with version 14 and 18 also installed

  1. I set the new default to be lts/hydrogen and set to 'use' the new default
  2. node -v returned version 18 as expected, but if the Terminal was restarted, the command returned version 16, even if nvm list was displaying the default alias as lts/hydrogen
  3. I removed version 16 to make sure 18 will be the default
  4. after a reboot, out of curiosity, I installed lts/gallium again and node -v this time returned version 18 as expected

For now I cannot inspect this any further, but I will make a note in the future if I notice anything

@ljharb
Copy link
Member

ljharb commented Jul 24, 2024

Thanks. It would have been helpful to know what the value of $PATH was during step 2, for future reference.

@attisimon
Copy link
Author

I have checked the $PATH when setting a different version as default, this time lts/iron, and it seems like the nvm version is reset to the last used value when restarting the terminal or app. However, if I restart the computer, the updated value appears in $PATH without any intervention.

@ljharb
Copy link
Member

ljharb commented Aug 20, 2024

@attisimon "reset to the last used value" is bizarre and not how nvm is supposed to work, i'd love to look through your profile files if that's an option :-)

@attisimon
Copy link
Author

attisimon commented Aug 20, 2024

We could also say that the new settings "do not stick", which sounds even more bizarre :)

.profile:

# Sample .profile for SUSE Linux
# rewritten by Christian Steinruecken <cstein@suse.de>
#
# This file is read each time a login shell is started.
# All other interactive shells will only read .bashrc; this is particularly
# important for language settings, see below.

test -z "$PROFILEREAD" && . /etc/profile || true

# Some applications read the EDITOR variable to determine your favourite text
# editor. So uncomment the line below and enter the editor of your choice :-)
#export EDITOR=/usr/bin/vim
#export EDITOR=/usr/bin/mcedit

# For some news readers it makes sense to specify the NEWSSERVER variable here
#export NEWSSERVER=your.news.server

# Some people don't like fortune. If you uncomment the following lines,
# you will have a fortune each time you log in ;-)

#if [ -x /usr/bin/fortune ] ; then
#    echo
#    /usr/bin/fortune
#    echo
#fi


# Added by Toolbox App
export PATH="$PATH:/home/username/.local/share/JetBrains/Toolbox/scripts"

.bashrc:

# Sample .bashrc for SUSE Linux
# Copyright (c) SUSE Software Solutions Germany GmbH

# There are 3 different types of shells in bash: the login shell, normal shell
# and interactive shell. Login shells read ~/.profile and interactive shells
# read ~/.bashrc; in our setup, /etc/profile sources ~/.bashrc - thus all
# settings made here will also take effect in a login shell.
#
# NOTE: It is recommended to make language settings in ~/.profile rather than
# here, since multilingual X sessions would not work properly if LANG is over-
# ridden in every subshell.

test -s ~/.alias && . ~/.alias || true

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

export PATH=$PATH:$HOME/.config/composer/vendor/bin

export ANDROID_HOME=/home/username/Android/Sdk/
export ANDROID_SDK_ROOT=/home/username/Android/Sdk/
export SAUCE_USERNAME="XXXXXX"
export SAUCE_ACCESS_KEY="XXXXXX"

export VDPAU_DRIVER="va_gl"

export CAPACITOR_ANDROID_STUDIO_PATH='/var/lib/flatpak/app/com.google.AndroidStudio/current/active/files/extra/android-studio/bin/studio.sh'

export SSH_ASKPASS=/usr/libexec/ssh/ksshaskpass

# env vars
export NEXUS_USERNAME=XXXXXX
export NEXUS_PASSWORD=XXXXXX
export PATH=$PATH:$HOME/Path/To/chromedriver/
export PATH=$PATH:$HOME/Path/To/maven/apache-maven-X.Y.Z/bin/


#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"

I also have nodejs22 installed from the default repos, but this was installed automatically as a dependency. I think this should not affect nvm.

Is there any other file I should look for?

@ljharb
Copy link
Member

ljharb commented Aug 20, 2024

.bash_profile or .zshrc, perhaps? everything in there looks fine tho (unfortunately).

Does SUSE have some kind of feature where it preserves the PATH and/or shell environment across sessions?

@attisimon
Copy link
Author

attisimon commented Aug 21, 2024

I don't have a .bash_profile.
.zshrc was created automatically by SDKMAN, but I don't have the zsh package installed. It contains the last section from .bashrc, required by SDKMAN.

I am not sure about such a SUSE feature, it would be strange though. Maybe I will open a thread in their forums to double-check.

@thomasfromont-adeo
Copy link

thomasfromont-adeo commented Sep 2, 2024

Hi,
I resolved the issue of "changing the default, but opening a new term still used the 'old' default."

It looked like I had multiple init of nvm from .profile and .bashrc and oh-my-zsh plugin, so I commented out most of the lines, set the default to v18, rebooted, set the default to lts/* and now every newly lauched term uses the lts/iron (v20) version like expected !

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

3 participants