Composer is not recognized as an internal or external command operable program or batch file error can occur due to two reasons, Composer is not installed properly or the Composer executable file is not found in the environment variables as a result of Windows, linux and mac Command Prompt. In this tutorial, we will show two solutions to fix this error in Windows, Linux, and Mac systems.
To fix this error, you can use following solutions:
- Solution 1: Add composer executable path to system’s PATH environment variable
- Solution 2: Uninstall and Reinstall Composer
Solution 1: Add composer executable path to system’s PATH environment variable
If you have installed the composer in your system. Now, you need to add Composer to the PATH environment variables, you can do the following:
- Step 1: Verify PHP Installation
- Step 2: Verify Composer Installation
- Step 3: Add Composer to System PATH
Step 1: Verify PHP Installation
Firstly, open a command prompt or terminal and run the following command into it to ensure PHP is correctly installed and in your system’s PATH:
php -v
Step 2: Verify Composer Installation
Once you have verified php installation, then you need to run the following command to check if Composer is correctly installed and accessible:
composer --version
If you still encounter the “composer is not recognized” error, proceed with the following steps to add Composer to your PATH in linux, windows or mac system.
Step 3: Add Composer to System PATH
If you are using Windows system, To add the composer executable path to the system PATH environment variable, you can do the following:
- Search for “Environment Variables” in your Windows search bar and select “Edit the system environment variables.”
- In the “System Properties” window, click the “Environment Variables” button.
- Under “System variables,” scroll down and find the “Path” variable. Select it and click “Edit.”
- In the “Edit Environment Variable” window, click “New” and add the path to your Composer installation. This is typically
C:\ProgramData\ComposerSetup\bin
, but it may vary depending on your installation location. - Click “OK” to close all the windows.
- Open a new command prompt or terminal and run
composer --version
again. You should now see Composer’s version information without the error.
If you are using linux or mac system, To add the composer executable path to the system PATH environment variable, you can do the following:
- Open a terminal window.
- Edit your shell’s profile configuration file (e.g.,
~/.bashrc
,~/.zshrc
, or~/.profile
) using a text editor. For example:- nano ~/.bashrc
- Add the following line at the end of the file, replacing
/path/to/composer
with the actual path to your Composer executable:- export PATH=”$PATH:/path/to/composer”
- Save and close the file.
- Run the following command to apply the changes to your current session:
- source ~/.bashrc
- Open a new terminal window and run
composer --version
again. You should now see Composer’s version information without the error.
Solution 2: Uninstall and Reinstall Composer
If you still found that Composer is not recognized as an internal or external command operable program or batch file. So you uninstall composer from system and also download it from the official website and install composer again.
Conclusion
That’s it, you should have resolved the “composer is not recognized as an internal or external command” error by using this tutorial. Composer should now be accessible from the command line, allowing you to manage your PHP dependencies seamlessly.