How To Add ~/.composer/vendor/bin To Your PATH?

Published August 23, 2024

Problem: Accessing Composer-Installed Executables

Adding the Composer bin directory to the PATH environment variable lets you access executables installed via Composer easily. Without this setup, you need to specify the full path to run these tools each time, which can be slow and inconvenient.

Adding ~/.composer/vendor/bin to PATH

Temporary Solution

To add the Composer bin directory to your PATH for the current terminal session:

  1. Open your terminal.
  2. Run this command:

    export PATH="$PATH:$HOME/.composer/vendor/bin"

This adds the Composer bin directory to your PATH for the current session only.

Tip: Verify PATH Addition

After running the export command, you can verify that the Composer bin directory has been added to your PATH by running:

echo $PATH

This will display your current PATH, and you should see the Composer bin directory included.

Permanent Solution for Bash Users

To make the change permanent for Bash users:

  1. Open your ~/.bashrc file with a text editor.

  2. Add this line at the end of the file:

    export PATH="$PATH:$HOME/.composer/vendor/bin"
  3. Save and close the file.

  4. To apply the changes without logging out, run:

    source ~/.bashrc

Alternative Locations for Other Systems

  • If your system doesn't have a ~/.bashrc file, you can add the export line to ~/.bash_profile.
  • For newer Laravel versions, you might need to use $HOME/.config/composer/vendor/bin instead of $HOME/.composer/vendor/bin.
  • To make the change system-wide, including for GUI applications, add the export line to ~/.profile.

Example: Using ~/.profile for System-Wide PATH Addition

To add the Composer bin directory to your PATH system-wide:

  1. Open your ~/.profile file with a text editor:
    nano ~/.profile
  2. Add the following line at the end of the file:
    export PATH="$PATH:$HOME/.composer/vendor/bin"
  3. Save and close the file.
  4. Log out and log back in for the changes to take effect.

Verifying the PATH Update

After adding the Composer bin directory to your PATH, you need to check if the changes were applied correctly. Here are two ways to check if the update worked:

Log out and log back in:

  1. Save your work and close all terminal windows.
  2. Log out of your Ubuntu system.
  3. Log back in to your account.
  4. Open a new terminal window.
  5. Type this command to show your current PATH:
    echo $PATH
  6. Look for the ~/.composer/vendor/bin directory in the output.

Use the source command to apply changes:

  1. If you don't want to log out, use the source command to reload your shell settings:
    source ~/.bashrc

    (Use ~/.bash_profile or ~/.profile if you added the PATH there)

  2. After running the source command, check your PATH:
    echo $PATH
  3. Look for the ~/.composer/vendor/bin directory in the output.

If you see the Composer bin directory in your PATH, the update was successful. You can now run Laravel commands without typing the full path to the executable.