fix(install): source uv env after installing uv (mirrors install.ps1)#2286
Open
ktwu01 wants to merge 1 commit into
Open
fix(install): source uv env after installing uv (mirrors install.ps1)#2286ktwu01 wants to merge 1 commit into
ktwu01 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 whatinstall.ps1already does on Windows (refreshes PATH from machine + user env after installing uv).Why
The bash installer pipes
https://astral.sh/uv/install.shintosh. 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 exportPATHin the current shell session, which is why it ends with the message:Two failure modes follow from kimi-cli's installer not sourcing that file:
~/.local/binis not on the bash subshell's PATH (fresh containers, fresh user accounts),command -v "$UV_BIN"returns non-zero right afterinstall_uv, and the script exits withError: uv not found after installation.~/.local/binis already on PATH,uv tool installsucceeds but the user's interactive shell may not have sourced the env yet, so the nextkimiinvocation returnscommand 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
shellcheck scripts/install.sh(with the existingSC1090disable directive for the dynamic.source).return+if/if→elif/else) is semantically identical to the original on the curl/wget/no-tool branches: same exit code, same error message.XDG_BIN_HOMEfallback 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 | bashfrom an external CDN). The fix is grounded in code reading + the upstream uv installer's documented behavior (the source athttps://releases.astral.sh/installers/uv/latest/uv-installer.shshows it writing to$INFERRED_HOME/.local/bin/envand editing~/.profile). If desired, a follow-up CI smoke test indebian:stable-slimwould catch this class of bug regressing.🤖 Generated with Claude Code