WSL2 Ubuntu18下Yarn全局安装Adonis CLI后命令无法调用问题
adonis: command not found After Global Installation via Yarn in WSL2 Ubuntu 18 Got it, let's break down why this is happening and how to fix it quickly:
Why does this happen?
When you run commands through your package.json scripts with Yarn, Yarn automatically adds the directory where global binaries are stored to the session's PATH environment variable. But when you run adonis directly in your terminal, your system's PATH doesn't include that directory—so it can't locate the command.
Step-by-step fix
1. Find Yarn's global binary directory
First, run this command to get the exact path where Yarn stores global binaries:
yarn global bin
You'll get an output like /home/your-username/.yarn/bin (the exact path depends on your user setup).
2. Check if this path is in your system's PATH
Run this to view your current PATH entries:
echo $PATH
If the path from yarn global bin isn't listed here, that's the root cause of your issue.
3. Add the path to PATH (temporary fix)
To make adonis work immediately in your current terminal session, run:
export PATH="$PATH:$(yarn global bin)"
Now try running adonis—it should work! Note: This change will reset when you close your terminal.
4. Add the path to PATH permanently
To make this fix stick across all terminal sessions:
- If you use Bash, open your
~/.bashrcfile with a text editor (like nano):nano ~/.bashrc - If you use Zsh, open
~/.zshrcinstead:nano ~/.zshrc - Add this line at the end of the file:
export PATH="$PATH:$(yarn global bin)" - Save and exit (for nano: press
Ctrl+O, hitEnter, thenCtrl+X). - Reload the configuration file to apply changes right away:
# For Bash source ~/.bashrc # For Zsh source ~/.zshrc
Now every time you open a new terminal, you'll be able to run adonis directly from the command line.
内容的提问来源于stack exchange,提问作者Evandro Pomatti

