Troubleshooting

Composer installs a global package but cannot find its command

Reviewed on 2 min read composer terminal

Many Composer packages include CLI binaries or executables that give you access to features from the command line.

The Laravel installer, for example, provides the laravel command. Creating a project may also require other programs depending on the options you choose.

The first step is to install the package globally in your account with composer global require:

composer global require "laravel/installer"

If running laravel makes the terminal reply command not found, first check that the installation finished correctly and that the package contains the binary:

composer global show laravel/installer
composer global config bin-dir --absolute

The second command returns the real binaries directory. Check that laravel exists there and run command -v laravel to find out whether the shell already finds it.

Only if the binary exists and its directory is not in PATH, add the path Composer returned to the shell's startup file. In Bash, for example:

export PATH="$PATH:/ruta/devuelta/por/composer"

Run source ~/.bashrc to apply the change if the session uses Bash. In another shell, edit its corresponding startup file.

Do not assume the path is always ~/.composer/vendor/bin: it can change depending on COMPOSER_HOME, XDG or Composer's bin-dir option.

If it finds the command but fails

First run laravel --version to confirm which binary you are using without creating a project. A permissions, PHP interpreter or requirements error is different from command not found and is not fixed by adding the directory to PATH again.

A cron job or a non-interactive session may not read ~/.bashrc. For those tasks, use verified absolute paths and the compatible PHP. Adding the directory at the end of PATH keeps the priority of an existing command with the same name; use command -v to detect that case before changing the order. Do not add directories that other users can write to.

You may also find useful

Something wrong or out of date? Tell us and we will review it.