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

使用Zsh执行命令时出现命令未找到错误的技术求助

Fix Zsh Command Not Found Errors & Regain Access to ~/.zshrc

It looks like your Zsh shell has a broken PATH environment variable—this is why basic system utilities like date, awk, wc, tr, and even nano aren’t being found. The Spaceship prompt errors are just a side effect, since it relies on those missing commands to function. Let’s fix this step by step:

1. Temporarily Restore PATH to Use Basic Commands

First, manually add the standard system directories to your PATH in the current shell. This will let you run commands like nano right away:

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:$PATH"

Test if this works by running date—it should output the current time without errors.

2. Edit Your Zsh Configuration File

Now you can open your ~/.zshrc file to fix the root issue:

nano ~/.zshrc

3. Fix the Permanent PATH Setup

Look for any lines that modify PATH in your config. Common mistakes include:

  • Overwriting PATH entirely (e.g., PATH="/custom/dir" instead of PATH="/custom/dir:$PATH")
  • Accidentally removing system directories from the PATH

Update your PATH line to include standard system directories. For example:

# Keep custom directories first, then append system PATH
export PATH="$HOME/.local/bin:$PATH"

# If you need a clean default, use this instead:
# export PATH="/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.local/bin"

4. Address the Spaceship Prompt Errors

Once your PATH is fixed, the Spaceship prompt errors should disappear automatically—since it will now find the date, awk, etc., commands it needs. If you still see issues later, double-check that the Spaceship theme is correctly installed (but this is secondary to the PATH problem).

5. Save Changes & Reload Zsh

In nano, press Ctrl+O to save the file, then Ctrl+X to exit. Reload your Zsh config to apply the permanent fix:

source ~/.zshrc

6. Verify Everything Works

Run commands like date, awk --version, and nano --version to confirm they work without errors. For the code command error: if you have VS Code installed, add its binary path to your ~/.zshrc (e.g., on macOS: export PATH="/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH").

内容的提问来源于stack exchange,提问作者Jônatas Souza Soares

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 09:12:41