Skip to content

Commit b63d095

Browse files
committed
fix(installer): persist Linux npm prefix path
1 parent 4d9aee4 commit b63d095

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Installer: after Linux NodeSource installs, prefer the newly installed supported Node binary when an older `/usr/local/bin/node` still shadows it on PATH.
6+
- Installer: when redirecting an unwritable Linux npm global prefix in a fresh home, create a `.bashrc` PATH hint so the next shell can find `openclaw`.
67

78
## 2026-05-03
89

public/install.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,11 +1719,18 @@ fix_npm_permissions() {
17191719

17201720
# shellcheck disable=SC2016
17211721
local path_line='export PATH="$HOME/.npm-global/bin:$PATH"'
1722+
local wrote_rc=0
17221723
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
1723-
if [[ -f "$rc" ]] && ! grep -q ".npm-global" "$rc"; then
1724-
echo "$path_line" >> "$rc"
1724+
if [[ -f "$rc" ]]; then
1725+
if ! grep -q ".npm-global" "$rc"; then
1726+
echo "$path_line" >> "$rc"
1727+
fi
1728+
wrote_rc=1
17251729
fi
17261730
done
1731+
if [[ "$wrote_rc" -eq 0 ]]; then
1732+
printf '%s\n' "$path_line" >> "$HOME/.bashrc"
1733+
fi
17271734

17281735
export PATH="$HOME/.npm-global/bin:$PATH"
17291736
ui_success "npm configured for user installs"

scripts/test-install-sh-unit.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,40 @@ EOF
476476
assert_eq "$got_version" "v24.13.0" "activate_supported_node_on_path active node version"
477477
)
478478

479+
echo "==> case: fix_npm_permissions creates bashrc PATH hint in fresh homes"
480+
(
481+
root="${TMP_DIR}/case-npm-prefix-fresh-home"
482+
home_dir="${root}/home"
483+
events="${root}/events.log"
484+
prefix="${root}/root-owned-prefix"
485+
mkdir -p "${home_dir}"
486+
487+
export OS="linux"
488+
export HOME="${home_dir}"
489+
export PATH="/usr/bin:/bin"
490+
491+
npm() {
492+
if [[ "${1:-}" == "config" && "${2:-}" == "get" && "${3:-}" == "prefix" ]]; then
493+
printf '%s\n' "${prefix}"
494+
return 0
495+
fi
496+
if [[ "${1:-}" == "config" && "${2:-}" == "set" && "${3:-}" == "prefix" ]]; then
497+
printf 'npm-set:%s\n' "${4:-}" >>"${events}"
498+
return 0
499+
fi
500+
return 1
501+
}
502+
ui_info() { :; }
503+
ui_warn() { :; }
504+
ui_success() { :; }
505+
506+
fix_npm_permissions
507+
508+
assert_contains "$(cat "${home_dir}/.bashrc")" '.npm-global/bin' "fix_npm_permissions fresh bashrc"
509+
got_path="${PATH%%:*}"
510+
assert_eq "$got_path" "${home_dir}/.npm-global/bin" "fix_npm_permissions active PATH"
511+
)
512+
479513
echo "==> case: npm diagnostics extractors"
480514
(
481515
root="${TMP_DIR}/case-npm-diagnostics"

0 commit comments

Comments
 (0)