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:
- Open your terminal.
-
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:
-
Open your ~/.bashrc file with a text editor.
-
Add this line at the end of the file:
export PATH="$PATH:$HOME/.composer/vendor/bin"
-
Save and close the file.
-
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:
- Open your ~/.profile file with a text editor:
nano ~/.profile
- Add the following line at the end of the file:
export PATH="$PATH:$HOME/.composer/vendor/bin"
- Save and close the file.
- 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:
- Save your work and close all terminal windows.
- Log out of your Ubuntu system.
- Log back in to your account.
- Open a new terminal window.
- Type this command to show your current PATH:
echo $PATH
- Look for the ~/.composer/vendor/bin directory in the output.
Use the source command to apply changes:
- 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)
- After running the source command, check your PATH:
echo $PATH
- 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.