Check and Analyze PATH
You are helping the user analyze what's on their PATH and suggest additions or improvements.
Your tasks:
Display current PATH:
echo $PATH | tr ':' '\n'Check which paths actually exist:
echo $PATH | tr ':' '\n' | while read p; do if [ -d "$p" ]; then echo "✓ $p" else echo "✗ $p (does not exist)" fi doneCheck for duplicate PATH entries:
echo $PATH | tr ':' '\n' | sort | uniq -dIdentify where PATH is being set: Check common locations:
grep -n "PATH" ~/.bashrc ~/.bash_profile ~/.profile /etc/environment /etc/profile 2>/dev/nullCheck for common development tool paths:
Programming languages:
- Python user packages:
~/.local/bin - Rust cargo:
~/.cargo/bin - Go:
~/go/binor$GOPATH/bin - Ruby gems: Check with
gem environment - Node/npm: Check with
npm config get prefix
Package managers:
- Homebrew:
/home/linuxbrew/.linuxbrew/bin - SDKMAN:
~/.sdkman/candidates/*/current/bin - pipx:
~/.local/bin
Version managers:
- pyenv:
~/.pyenv/bin - rbenv:
~/.rbenv/bin - nvm: (check ~/.nvm/)
- asdf:
~/.asdf/bin
System tools:
- User binaries:
~/bin,~/.local/bin - Snap:
/snap/bin - Flatpak:
/var/lib/flatpak/exports/bin
- Python user packages:
Check what's installed in each PATH directory: For each directory in PATH:
echo "Contents of $dir:" ls -la "$dir" | head -10Suggest missing common paths: Check and suggest if not in PATH:
~/.local/bin(Python user packages, pipx)~/bin(User scripts)~/.cargo/bin(Rust packages)~/go/bin(Go packages)/snap/bin(Snap packages)~/.npm-global/bin(npm global packages)
For each missing path that has executables, suggest adding it.
Check for security issues:
- Warn if
.(current directory) is in PATH - Warn if world-writable directories are in PATH:
echo $PATH | tr ':' '\n' | while read p; do if [ -d "$p" ] && [ -w "$p" ]; then ls -ld "$p" fi done
- Warn if
Check PATH order/precedence: Explain that earlier paths take precedence. Show which binary would be executed:
which -a python python3 java gcc git node npmCheck for conflicting tools:
type -a python type -a python3 type -a javaSuggest PATH organization: Recommended order:
- User binaries (
~/bin,~/.local/bin) - Version managers (pyenv, rbenv, nvm)
- Language-specific paths (cargo, go)
- Homebrew
- System binaries (
/usr/local/bin,/usr/bin,/bin)
- User binaries (
Check environment-specific paths:
Python:
python3 -m site --user-base # Suggests adding $(python3 -m site --user-base)/binNode/npm:
npm config get prefix # Suggests adding <prefix>/binGo:
go env GOPATH # Suggests adding $GOPATH/binRust:
echo $CARGO_HOME # Suggests adding ~/.cargo/binGenerate suggested PATH setup: Based on findings, create suggested additions for ~/.bashrc:
# User binaries export PATH="$HOME/bin:$PATH" export PATH="$HOME/.local/bin:$PATH" # Python export PATH="$HOME/.local/bin:$PATH" # Rust export PATH="$HOME/.cargo/bin:$PATH" # Go export PATH="$HOME/go/bin:$PATH" # SDKMAN # Added by sdkman-init.sh # pyenv export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)" # Homebrew eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"Check for broken symlinks in PATH:
echo $PATH | tr ':' '\n' | while read dir; do if [ -d "$dir" ]; then find "$dir" -maxdepth 1 -type l ! -exec test -e {} \; -print 2>/dev/null fi doneProvide recommendations:
- Remove non-existent directories from PATH
- Add missing common paths that have executables
- Fix duplicate entries
- Correct PATH order if needed
- Remove security issues (
.in PATH, world-writable dirs) - Consolidate PATH modifications into one file (prefer ~/.bashrc)
- Document what each PATH addition is for
Show how to temporarily modify PATH:
# Add to front (takes precedence) export PATH="/new/path:$PATH" # Add to end export PATH="$PATH:/new/path" # Remove from PATH export PATH=$(echo $PATH | tr ':' '\n' | grep -v "/path/to/remove" | tr '\n' ':')Show how to make PATH changes permanent:
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
Important notes:
- Changes to PATH only affect current shell unless made permanent
- Order matters - earlier paths have precedence
- Don't add current directory (
.) to PATH - Use absolute paths when possible
- Source ~/.bashrc after changes:
source ~/.bashrc - Some tools (pyenv, conda, nvm) modify PATH dynamically
- Check for PATH modifications in multiple files