You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 18.04下无法升级AWS SAM CLI从0.2.11到0.3.0

Fixing AWS SAM CLI Upgrade Issue on Ubuntu 18.04 LTS (0.2.11 → 0.3.0)

Hey there, let's work through this SAM CLI upgrade problem together. I've dealt with similar conflicts between npm and pip installations before, so here's a step-by-step fix to get you to version 0.3.0:

Step 1: Fully Clean Up Old SAM CLI Installations

The root issue is likely conflicting installations (npm's aws-sam-local and pip's aws-sam-cli) or leftover files blocking the upgrade.

  • First, check which version is currently active and where it's installed:

    which sam || which aws-sam-local
    

    This will show you the path to the executable that's running (e.g., /usr/local/bin/sam or ~/.local/bin/sam).

  • Remove npm-installed files (even if npm uninstall -g aws-sam-local failed):

    1. Find npm's global module directory:
      npm root -g
      
    2. Delete the aws-sam-local folder from that directory (e.g., /usr/local/lib/node_modules/aws-sam-local).
    3. Delete the corresponding executable file (e.g., /usr/local/bin/aws-sam-local or /usr/local/bin/sam).
  • Remove pip-installed remnants:

    1. Check where pip2 installed SAM CLI:
      pip2 show aws-sam-cli
      
    2. Go to the Location path listed (e.g., ~/.local/lib/python2.7/site-packages) and delete all folders/files related to AWS SAM CLI:
      • aws_sam_cli-* directories
      • aws_sam_cli-*.egg-info files

Step 2: Formal Uninstall via pip

Run this to ensure pip recognizes the old version is gone:

pip2 uninstall -y aws-sam-cli

It might say "not installed"—that's okay, we already cleaned up the files manually.

Step 3: Install Exact Version 0.3.0

Specify the version number to avoid ambiguity during installation:

pip2 install --user aws-sam-cli==0.3.0

The --user flag installs it in your home directory, avoiding permission issues.

Step 4: Ensure Your PATH Includes the Install Directory

Ubuntu might not have ~/.local/bin (where --user installs executables) in your PATH by default. Check with:

echo $PATH

If you don't see ~/.local/bin, add it to your shell config:

  1. Open ~/.bashrc in a text editor:
    nano ~/.bashrc
    
  2. Add this line at the bottom:
    export PATH="$HOME/.local/bin:$PATH"
    
  3. Save and reload the config:
    source ~/.bashrc
    

Step 5: Verify the Upgrade

Clear cached command references and check the version:

hash -r
sam --version

You should now see 0.3.0 as the installed version.

Why This Happened

Early versions of SAM CLI were distributed via npm as aws-sam-local, but later versions switched to pip as aws-sam-cli. If you had both installations, the old npm version might have taken precedence in your PATH, making you think the pip upgrade didn't work. Cleaning up both sets of files ensures the new pip-installed version is the only one running.

内容的提问来源于stack exchange,提问作者Ashu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:39:22