Skip to content

fix(uninstall): source nvm before npm uninstall to find the correct p…#1965

Open
swqa-saiy wants to merge 1 commit intoNVIDIA:mainfrom
swqa-saiy:fix/uninstall-nvm-path
Open

fix(uninstall): source nvm before npm uninstall to find the correct p…#1965
swqa-saiy wants to merge 1 commit intoNVIDIA:mainfrom
swqa-saiy:fix/uninstall-nvm-path

Conversation

@swqa-saiy
Copy link
Copy Markdown

@swqa-saiy swqa-saiy commented Apr 16, 2026

Summary

Source nvm.sh before running npm uninstall -g nemoclaw in the curl-based uninstaller, and add a fallback that removes any leftover nemoclaw binary found under an nvm prefix.

Related Issue

Fixes #1959

Changes

  • Add ensure_nvm_for_uninstall() that sources ~/.nvm/nvm.sh so npm resolves to the nvm-managed prefix
  • Call it at the start of remove_nemoclaw_cli() before any npm operations
  • Add post-uninstall fallback: if nemoclaw is still found under ~/.nvm/*/bin/, remove the binary and its lib/node_modules/nemoclaw entry directly
  • Covers edge case where nvm's default alias points to a different Node.js version than the one used during install

Root cause: curl | bash runs in a non-interactive shell that does not source .bashrc/.zshrc, so nvm is not loaded. npm uninstall -g either fails (npm not on PATH) or targets the wrong global prefix (system npm vs nvm npm), leaving ~/.nvm/versions/node/v22.x/bin/nemoclaw behind.

nemoclaw uninstall --yes was unaffected because it runs from the nvm-installed Node.js which already has the correct npm on PATH.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Verification

  • npx prek run --all-files passes
  • npm test passes
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes

Manual test results

Tested on local machine (nvm v22.22.1, Ubuntu 22.04):

Scenario Result
env -i clean shell (no nvm) + old code ❌ npm not found, nemoclaw left behind
env -i clean shell + new code (source nvm) ✅ npm found, nemoclaw removed
npm uninstall succeeds but binary remains (version mismatch) ✅ fallback rm removes leftover

AI Disclosure

  • AI-assisted — tool: OpenClaw (Claude)

Signed-off-by: swqa-saiy swqa-saiy@users.noreply.github.com

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the uninstall process to completely remove all installation artifacts and leftover files that were previously left behind.
    • Enhanced compatibility with Node Version Manager installations to ensure comprehensive cleanup.
    • Improved removal of remaining binaries across different installation paths.

…refix

When running uninstall.sh via `curl | bash`, nvm is not loaded into
the shell environment. This means `command -v npm` either fails
(npm not on PATH) or finds a system npm whose global prefix differs
from the nvm-managed one used during install. In both cases,
`npm uninstall -g nemoclaw` does not remove the binary installed
under the nvm prefix (e.g. ~/.nvm/versions/node/v22.x/bin/nemoclaw).

Source nvm.sh at the start of remove_nemoclaw_cli() so npm resolves
to the same prefix that originally installed nemoclaw.

Running `nemoclaw uninstall` was not affected because the command
itself runs from the nvm-installed Node.js, which already has the
correct npm on PATH.

Fixes NVIDIA#1959

Signed-off-by: swqa-saiy <swqa-saiy@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2026

📝 Walkthrough

Walkthrough

This PR fixes an incomplete uninstall process by adding NVM directory awareness to the uninstall script. It introduces a helper function to source NVM, then extends cleanup logic to remove leftover nemoclaw binaries and modules from NVM-managed Node.js directories.

Changes

Cohort / File(s) Summary
NVM-aware Uninstall Enhancement
uninstall.sh
Added ensure_nvm_for_uninstall() helper function to source nvm.sh when available. Extended remove_nemoclaw_cli() to detect and remove leftover nemoclaw binaries under ~/.nvm and clean up corresponding lib/node_modules/nemoclaw directory after npm operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Through NVM paths the rabbit hops,
Leftover binaries must all be dropped,
With careful cleanup, source by source,
Uninstall now runs its proper course!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: sourcing nvm before npm uninstall to find the correct prefix, which directly addresses the root cause documented in issue #1959.
Linked Issues check ✅ Passed The PR implementation directly addresses all coding requirements from issue #1959: sourcing nvm before npm operations to resolve the correct prefix, and adding fallback cleanup for leftover binaries.
Out of Scope Changes check ✅ Passed All changes in uninstall.sh are directly related to fixing the nvm-related uninstall issue; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@uninstall.sh`:
- Around line 383-399: The current cleanup only runs when command -v nemoclaw
finds a binary and therefore misses leftover installs in other NVM prefixes;
change the logic in the block using remaining/mod_dir to instead scan
${NVM_DIR:-$HOME/.nvm}/versions/node/* for versions containing bin/nemoclaw and
lib/node_modules/nemoclaw and remove them regardless of PATH. Concretely,
replace the outer "if command -v nemoclaw" guard with a loop over
"${NVM_DIR:-$HOME/.nvm}/versions/node" entries, for each candidate check for
"$candidate/bin/nemoclaw" and remove it (logging via info "Removed leftover
nemoclaw binary at ...") and then check and rm -rf
"$candidate/lib/node_modules/nemoclaw" (logging as well); preserve the existing
variable names (remaining/mod_dir) or use descriptive equivalents and keep
redirects like 2>/dev/null to avoid errors when directories are absent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ade8f5cf-70f8-4659-a509-7e39b5b34d22

📥 Commits

Reviewing files that changed from the base of the PR and between c038795 and 5cbf65b.

📒 Files selected for processing (1)
  • uninstall.sh

Comment thread uninstall.sh
Comment on lines +383 to +399
# Belt-and-suspenders: if nemoclaw is still on PATH after npm uninstall
# (e.g. nvm resolved to a different node version than the one used during
# install), try to remove it from all nvm prefixes.
if command -v nemoclaw >/dev/null 2>&1; then
local remaining
remaining="$(command -v nemoclaw 2>/dev/null || true)"
if [ -n "$remaining" ] && [[ "$remaining" == */.nvm/* ]]; then
rm -f "$remaining"
info "Removed leftover nemoclaw binary at $remaining"
# Also clean the lib/node_modules symlink if present.
local mod_dir
mod_dir="$(dirname "$(dirname "$remaining")")/lib/node_modules/nemoclaw"
if [ -e "$mod_dir" ]; then
rm -rf "$mod_dir"
fi
fi
fi
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.

⚠️ Potential issue | 🟠 Major

The fallback still misses the version-mismatch residue it is meant to clean.

This block only runs if command -v nemoclaw still succeeds. If npm uninstall -g removes the currently active prefix but leaves another nemoclaw under a different ${NVM_DIR}/versions/node/* tree, command -v is empty and the leftover is never touched. The */.nvm/* check also skips custom NVM_DIR locations.

Scan ${NVM_DIR:-$HOME/.nvm}/versions/node directly instead of gating cleanup on PATH resolution.

Suggested fix
-  # Belt-and-suspenders: if nemoclaw is still on PATH after npm uninstall
-  # (e.g. nvm resolved to a different node version than the one used during
-  # install), try to remove it from all nvm prefixes.
-  if command -v nemoclaw >/dev/null 2>&1; then
-    local remaining
-    remaining="$(command -v nemoclaw 2>/dev/null || true)"
-    if [ -n "$remaining" ] && [[ "$remaining" == */.nvm/* ]]; then
-      rm -f "$remaining"
-      info "Removed leftover nemoclaw binary at $remaining"
-      # Also clean the lib/node_modules symlink if present.
-      local mod_dir
-      mod_dir="$(dirname "$(dirname "$remaining")")/lib/node_modules/nemoclaw"
-      if [ -e "$mod_dir" ]; then
-        rm -rf "$mod_dir"
-      fi
-    fi
-  fi
+  # Belt-and-suspenders: clean any leftover nemoclaw installs from nvm-managed
+  # node prefixes, even if the active PATH no longer points at them.
+  local nvm_dir="${NVM_DIR:-$HOME/.nvm}"
+  if [ -d "$nvm_dir/versions/node" ]; then
+    local remaining mod_dir
+    while IFS= read -r -d '' remaining; do
+      rm -f "$remaining"
+      info "Removed leftover nemoclaw binary at $remaining"
+    done < <(find "$nvm_dir/versions/node" -path '*/bin/nemoclaw' -print0 2>/dev/null)
+
+    while IFS= read -r -d '' mod_dir; do
+      rm -rf "$mod_dir"
+      info "Removed leftover nemoclaw module at $mod_dir"
+    done < <(find "$nvm_dir/versions/node" -path '*/lib/node_modules/nemoclaw' -print0 2>/dev/null)
+  fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Belt-and-suspenders: if nemoclaw is still on PATH after npm uninstall
# (e.g. nvm resolved to a different node version than the one used during
# install), try to remove it from all nvm prefixes.
if command -v nemoclaw >/dev/null 2>&1; then
local remaining
remaining="$(command -v nemoclaw 2>/dev/null || true)"
if [ -n "$remaining" ] && [[ "$remaining" == */.nvm/* ]]; then
rm -f "$remaining"
info "Removed leftover nemoclaw binary at $remaining"
# Also clean the lib/node_modules symlink if present.
local mod_dir
mod_dir="$(dirname "$(dirname "$remaining")")/lib/node_modules/nemoclaw"
if [ -e "$mod_dir" ]; then
rm -rf "$mod_dir"
fi
fi
fi
# Belt-and-suspenders: clean any leftover nemoclaw installs from nvm-managed
# node prefixes, even if the active PATH no longer points at them.
local nvm_dir="${NVM_DIR:-$HOME/.nvm}"
if [ -d "$nvm_dir/versions/node" ]; then
local remaining mod_dir
while IFS= read -r -d '' remaining; do
rm -f "$remaining"
info "Removed leftover nemoclaw binary at $remaining"
done < <(find "$nvm_dir/versions/node" -path '*/bin/nemoclaw' -print0 2>/dev/null)
while IFS= read -r -d '' mod_dir; do
rm -rf "$mod_dir"
info "Removed leftover nemoclaw module at $mod_dir"
done < <(find "$nvm_dir/versions/node" -path '*/lib/node_modules/nemoclaw' -print0 2>/dev/null)
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@uninstall.sh` around lines 383 - 399, The current cleanup only runs when
command -v nemoclaw finds a binary and therefore misses leftover installs in
other NVM prefixes; change the logic in the block using remaining/mod_dir to
instead scan ${NVM_DIR:-$HOME/.nvm}/versions/node/* for versions containing
bin/nemoclaw and lib/node_modules/nemoclaw and remove them regardless of PATH.
Concretely, replace the outer "if command -v nemoclaw" guard with a loop over
"${NVM_DIR:-$HOME/.nvm}/versions/node" entries, for each candidate check for
"$candidate/bin/nemoclaw" and remove it (logging via info "Removed leftover
nemoclaw binary at ...") and then check and rm -rf
"$candidate/lib/node_modules/nemoclaw" (logging as well); preserve the existing
variable names (remaining/mod_dir) or use descriptive equivalents and keep
redirects like 2>/dev/null to avoid errors when directories are absent.

@wscurran wscurran added good first issue Good for newcomers fix labels Apr 16, 2026
@wscurran
Copy link
Copy Markdown
Contributor

✨ Thanks for submitting this PR that proposes a fix for the uninstall command not removing the NemoClaw CLI, which could help improve the uninstall process and is a good first issue for new contributors.


Possibly related open issues:

@wscurran wscurran added NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI). and removed good first issue Good for newcomers labels Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix NemoClaw CLI Use this label to identify issues with the NemoClaw command-line interface (CLI).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NemoClaw][All Platforms][Docs][Uninstall] curl bash uninstall didn't remove nemoclaw cli

2 participants