---
title: "command not found after installing a package"
description: "You installed a tool but the shell says command not found. Learn how PATH works, where to add directories, and when to run hash -r or reload your rc file."
url: https://www.danny.engineering/answer/bash/command-not-found-after-installing-a-package
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:25:00.000Z
tags: ["Bash"]
---

# command not found after installing a package

## The short answer


The shell cannot find the program because the directory it was installed into is not on your `PATH`, or your current shell has not picked up the change yet. Find where the binary lives, add that directory to `PATH` in your shell's startup file, then reload it.


```bash
# Example: the tool was installed into ~/.local/bin
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
hash -r
```


On macOS the default shell is zsh, so use `~/.zshrc` instead of `~/.bashrc`.


## Why it happens


When you type a command name without a slash, the shell looks through each directory listed in the `PATH` variable, in order, and runs the first match. If none of them contain the program, you get `command not found`.


```bash
echo "$PATH" | tr ':' '\n'
```


Package managers and installers often put binaries in places that are not on `PATH` by default, for example:

- `~/.local/bin` (pip with `--user`, pipx, many install scripts)
- `~/.cargo/bin` (Rust tools)
- `~/go/bin` (Go tools)
- the global bin folder of npm, pnpm or a Node version manager
- `/opt/homebrew/bin` on Apple Silicon Macs

Even when an installer edits your startup file for you, the shell you already have open read that file when it started. It will not see the change until you reload it or open a new terminal.


There is one more layer. Bash remembers where it found each command in a hash table, so it does not search `PATH` every time. If a command moved, or you installed a newer copy earlier in `PATH`, Bash may keep using the old location until you clear that cache.


## How to fix it


### Find where the program was installed


Check the installer's output first. If it scrolled away, these help:


```bash
# Does the shell already know about it?
command -v mytool
type -a mytool

# Where did the package manager put it?
npm prefix -g          # npm global bin lives in this folder's bin
pip show -f mypackage  # lists installed files
ls ~/.local/bin ~/.cargo/bin ~/go/bin 2>/dev/null
```


### Add the directory to PATH in the right file


Put the export in the file your shell reads for interactive sessions:


| Shell                        | File to edit      |
| ---------------------------- | ----------------- |
| Bash on Linux                | `~/.bashrc`       |
| Bash on macOS (login shells) | `~/.bash_profile` |
| zsh (macOS default)          | `~/.zshrc`        |


```bash
export PATH="$HOME/.local/bin:$PATH"
```


Putting the new directory first means its programs win over older system copies. Putting it last (`PATH="$PATH:$HOME/.local/bin"`) means system copies win. Pick deliberately.


On many Linux distributions, `~/.bash_profile` or `~/.profile` sources `~/.bashrc`, so editing `~/.bashrc` covers both login and non-login shells. If you are unsure, check that file for a line that sources `~/.bashrc`.


### Reload the shell


```bash
source ~/.bashrc   # or: source ~/.zshrc
```


Opening a new terminal tab works too. Running `exec "$SHELL" -l` replaces the current shell with a fresh login shell.


### Clear the command cache


If the command exists on `PATH` but the shell still runs an old copy, or reports `No such file or directory` for a path that has since moved, clear the hash table:


```bash
hash -r     # Bash
rehash      # zsh
```


### Check scripts, cron and CI separately


Non-interactive shells, cron jobs, systemd services and CI runners do not read `~/.bashrc`. If a command works in your terminal but not in a script or job, either use the full path to the binary or set `PATH` at the top of the script or job definition.


```bash
#!/usr/bin/env bash
export PATH="$HOME/.local/bin:$PATH"
mytool --version
```


## Common pitfalls

- Using single quotes inside the export, such as `export PATH='$HOME/bin:$PATH'`. Single quotes stop expansion, so `PATH` becomes the literal text and almost every command breaks. Use double quotes.
- Overwriting `PATH` entirely with `export PATH="$HOME/bin"`, which removes `/usr/bin` and friends. Always include the existing `$PATH`.
- Editing `~/.bashrc` while your shell is actually zsh. Check with `echo "$SHELL"` or `ps -p $$`.
- Adding the same line many times while experimenting. It works but makes `PATH` long and confusing; tidy it up.
- Installing with `sudo npm install -g` or `sudo pip install` to make a command appear. This can create permission problems later. Prefer a user-level install directory on your `PATH`.

## Related reading

- [Bash Reference Manual: Bash Startup Files](https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html)
- [Bash Reference Manual: Bourne Shell Builtins (hash)](https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html)
