Skip to content

fix(installer): source nvm before Node detection (#49556)#49594

Open
eliot-onbox wants to merge 1 commit intoopenclaw:mainfrom
eliot-onbox:fix/nvm-node-detection-49556
Open

fix(installer): source nvm before Node detection (#49556)#49594
eliot-onbox wants to merge 1 commit intoopenclaw:mainfrom
eliot-onbox:fix/nvm-node-detection-49556

Conversation

@eliot-onbox
Copy link
Copy Markdown

Problem

When the installer runs via curl -fsSL https://openclaw.ai/install.sh | bash, shell profile files (.bashrc, .zshrc) are not sourced. This means nvm's PATH modifications are missing and command -v node finds the system Node (e.g. v8 at /usr/local/bin/node) instead of the nvm-managed version (e.g. v22 at ~/.nvm/versions/node/v22.x/bin/node).

The installer then unnecessarily tries to install/upgrade Node, or errors out telling the user to fix their PATH manually.

Fix

Source nvm.sh before check_node() is called, so nvm-managed Node versions appear on PATH:

if [[ -z "${NVM_DIR:-}" && -d "${HOME}/.nvm" ]]; then
    export NVM_DIR="${HOME}/.nvm"
fi
if [[ -n "${NVM_DIR:-}" && -s "${NVM_DIR}/nvm.sh" ]]; then
    . "${NVM_DIR}/nvm.sh" 2>/dev/null || true
fi
  • Respects NVM_DIR if already set
  • Falls back to ~/.nvm (the default nvm install location)
  • Suppresses any nvm output with 2>/dev/null
  • Failure is non-fatal (|| true)

Scope

This PR only addresses nvm. Other version managers (fnm, volta, asdf, mise) are not handled — that could be a follow-up if needed.

Fixes #49556

When the installer runs via curl|bash, .bashrc/.zshrc are not sourced.
This means nvm's PATH modifications are missing and the system Node
(e.g. v8) is found instead of the nvm-managed version (e.g. v22).

Fix: source nvm.sh before check_node() so nvm-managed Node versions
appear on PATH. Respects NVM_DIR if set, falls back to ~/.nvm.

Fixes openclaw#49556
@openclaw-barnacle openclaw-barnacle bot added scripts Repository scripts size: XS labels Mar 18, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 18, 2026

Greptile Summary

This PR fixes a real and well-understood problem: when the installer is piped through curl | bash, shell profiles are not sourced, so nvm's PATH modifications are absent and the system Node (potentially an old version) is found instead of the user's nvm-managed one. The fix correctly sources nvm.sh before check_node() is called.

Changes

  • Adds a two-block guard in main() to set NVM_DIR (if unset and ~/.nvm exists) and then source nvm.sh before the Node detection step
  • Failure is non-fatal (|| true) and the guard is safe to run even when nvm is absent

Minor issue found

  • 2>/dev/null only suppresses stderr; nvm can emit informational messages to stdout (e.g. "Now using node v22.x.x") that would appear inline with the installer's formatted output. The script already uses &>/dev/null elsewhere; using it here would match the PR description's intent of suppressing "any nvm output".

Confidence Score: 4/5

  • Safe to merge; the fix is minimal, non-breaking, and correctly solves the curl|bash nvm PATH problem.
  • The logic is sound and addresses a clear real-world failure mode. The only finding is a minor stdout-vs-stderr suppression discrepancy that can pollute installer output but won't cause incorrect behaviour.
  • No files require special attention beyond the single-line suggestion on scripts/install.sh:2350.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: scripts/install.sh
Line: 2350

Comment:
**Stdout from nvm.sh not suppressed**

`2>/dev/null` only redirects stderr. When `nvm.sh` is sourced it can print to stdout — for example, if a `.nvmrc` or default alias is set, nvm may emit `"Now using node v22.x.x"` on stdout. This would appear unexpectedly in the middle of the installer's own formatted output.

The PR description says _"Suppresses any nvm output with `2>/dev/null`"_, but that claim only holds for stderr. Use `&>/dev/null` (bash-specific, already used elsewhere in this script) to redirect both streams:

```suggestion
        . "${NVM_DIR}/nvm.sh" &>/dev/null || true
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "fix(installer): sour..."

export NVM_DIR="${HOME}/.nvm"
fi
if [[ -n "${NVM_DIR:-}" && -s "${NVM_DIR}/nvm.sh" ]]; then
. "${NVM_DIR}/nvm.sh" 2>/dev/null || true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Stdout from nvm.sh not suppressed

2>/dev/null only redirects stderr. When nvm.sh is sourced it can print to stdout — for example, if a .nvmrc or default alias is set, nvm may emit "Now using node v22.x.x" on stdout. This would appear unexpectedly in the middle of the installer's own formatted output.

The PR description says "Suppresses any nvm output with 2>/dev/null", but that claim only holds for stderr. Use &>/dev/null (bash-specific, already used elsewhere in this script) to redirect both streams:

Suggested change
. "${NVM_DIR}/nvm.sh" 2>/dev/null || true
. "${NVM_DIR}/nvm.sh" &>/dev/null || true
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/install.sh
Line: 2350

Comment:
**Stdout from nvm.sh not suppressed**

`2>/dev/null` only redirects stderr. When `nvm.sh` is sourced it can print to stdout — for example, if a `.nvmrc` or default alias is set, nvm may emit `"Now using node v22.x.x"` on stdout. This would appear unexpectedly in the middle of the installer's own formatted output.

The PR description says _"Suppresses any nvm output with `2>/dev/null`"_, but that claim only holds for stderr. Use `&>/dev/null` (bash-specific, already used elsewhere in this script) to redirect both streams:

```suggestion
        . "${NVM_DIR}/nvm.sh" &>/dev/null || true
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 631caec633

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

export NVM_DIR="${HOME}/.nvm"
fi
if [[ -n "${NVM_DIR:-}" && -s "${NVM_DIR}/nvm.sh" ]]; then
. "${NVM_DIR}/nvm.sh" 2>/dev/null || true
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Source nvm in --no-use mode

Sourcing nvm.sh directly here can change the active Node version before check_node() runs, because nvm.sh defaults to nvm_process_parameters auto mode use and will switch from a system Node to the default nvm alias. In environments where PATH already has a valid system Node (e.g. v24) but nvm default is older (e.g. v18), this makes the installer mis-detect Node as unsupported, trigger unnecessary installation, and potentially fail on hosts without sudo. Load nvm with --no-use (or equivalent) so we detect availability without mutating the active runtime.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scripts Repository scripts size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Installer script does not respect nvm Node version (detects system Node instead)

1 participant