Skip to content

fix(install): source uv env after installing uv (mirrors install.ps1)#2286

Open
ktwu01 wants to merge 1 commit into
MoonshotAI:mainfrom
ktwu01:fix/install-sh-source-uv-env
Open

fix(install): source uv env after installing uv (mirrors install.ps1)#2286
ktwu01 wants to merge 1 commit into
MoonshotAI:mainfrom
ktwu01:fix/install-sh-source-uv-env

Conversation

@ktwu01
Copy link
Copy Markdown

@ktwu01 ktwu01 commented May 14, 2026

Resolves #2272.

Change

Source uv's env script (${XDG_BIN_HOME:-$HOME/.local/bin}/env) after the upstream uv installer runs, with a PATH-export fallback for older uv versions. Mirrors what install.ps1 already does on Windows (refreshes PATH from machine + user env after installing uv).

Why

The bash installer pipes https://astral.sh/uv/install.sh into sh. The upstream uv installer puts the binary in ${XDG_BIN_HOME:-$HOME/.local/bin} and writes shell rc entries for future shells — it does NOT export PATH in the current shell session, which is why it ends with the message:

To add $HOME/.local/bin to your PATH, either restart your shell or run:
source $HOME/.local/bin/env

Two failure modes follow from kimi-cli's installer not sourcing that file:

  1. Hard fail (script aborts). On systems where ~/.local/bin is not on the bash subshell's PATH (fresh containers, fresh user accounts), command -v "$UV_BIN" returns non-zero right after install_uv, and the script exits with Error: uv not found after installation.
  2. Soft fail. When ~/.local/bin is already on PATH, uv tool install succeeds but the user's interactive shell may not have sourced the env yet, so the next kimi invocation returns command not found.

The Windows installer doesn't have this bug because it explicitly refreshes the session PATH from machine + user env vars after installing uv. This PR brings install.sh to parity.

Diff

 install_uv() {
   if command -v curl >/dev/null 2>&1; then
     curl -fsSL https://astral.sh/uv/install.sh | sh
-    return
-  fi
-
-  if command -v wget >/dev/null 2>&1; then
+  elif command -v wget >/dev/null 2>&1; then
     wget -qO- https://astral.sh/uv/install.sh | sh
-    return
+  else
+    echo "Error: curl or wget is required to install uv." >&2
+    exit 1
   fi

-  echo "Error: curl or wget is required to install uv." >&2
-  exit 1
+  # The upstream uv installer writes ${XDG_BIN_HOME:-$HOME/.local/bin}/env and
+  # prints "Run 'source ...' to add uv to your PATH" — but it does not source
+  # the file itself. Source it here so the rest of THIS script (and the user's
+  # immediate `kimi` invocation) can find uv on PATH.
+  uv_env="${XDG_BIN_HOME:-$HOME/.local/bin}/env"
+  if [ -f "$uv_env" ]; then
+    # shellcheck disable=SC1090
+    . "$uv_env"
+  else
+    # Fallback for older uv installers that may not write an env script.
+    export PATH="${XDG_BIN_HOME:-$HOME/.local/bin}:$PATH"
+  fi
 }

Verification

  • Passes shellcheck scripts/install.sh (with the existing SC1090 disable directive for the dynamic . source).
  • The control flow change (drop return + if/ifelif/else) is semantically identical to the original on the curl/wget/no-tool branches: same exit code, same error message.
  • XDG_BIN_HOME fallback handles non-default uv install dirs.

Honest scope

I have not run the installer end-to-end on a fresh container myself in this session (would require piping curl | bash from an external CDN). The fix is grounded in code reading + the upstream uv installer's documented behavior (the source at https://releases.astral.sh/installers/uv/latest/uv-installer.sh shows it writing to $INFERRED_HOME/.local/bin/env and editing ~/.profile). If desired, a follow-up CI smoke test in debian:stable-slim would catch this class of bug regressing.

🤖 Generated with Claude Code


Open in Devin Review

The bash installer downloads uv (which puts the binary in
${XDG_BIN_HOME:-$HOME/.local/bin} and writes an env script there
but does NOT touch the running shell's PATH). The current shell
therefore can't find uv on PATH unless it was already there.

Two failure modes follow:
  1. Hard fail: 'command -v uv' returns non-zero immediately after
     install_uv on systems where ~/.local/bin is not pre-baked into
     PATH, and the script exits with 'Error: uv not found after
     installation.'
  2. Soft fail: when ~/.local/bin happens to be on PATH already,
     'uv tool install' succeeds but the user's next 'kimi' call
     still fails with 'command not found' if their interactive
     shell hasn't sourced the env yet.

Fix: source ${XDG_BIN_HOME:-$HOME/.local/bin}/env after installing
uv, with a PATH-export fallback for older uv installers that may
not write the env script. This mirrors what install.ps1 already
does on Windows (refreshes PATH from machine + user env after
installing uv).

Refs MoonshotAI#2272.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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

Successfully merging this pull request may close these issues.

[Bug] install.sh doesn't source uv's env after installing it: first-time users get "uv not found" or "kimi: command not found"

2 participants