Composer Install Options

Vitaliy Dotsenko
Legacybeta
Published in
2 min readMay 22, 2020
https://icons8.com

Composer is a single file cross-platform CLI application for managing dependencies in the PHP applications. It’s doing the same stuff as npm for Node.js.

Composer is PHAR compressed file with .phar file extension, it supported operating systems like Windows, Linux, macOS, and required PHP version more than 5.3.2.

Homebrew on macOS

By far the easiest way to install composer on macOS is with Homebrew; a package manager for macOS. Ruby scripts to make your life easier, should be their tagline.

brew install composer

You can test it working correctly and also to see what version of composer you have installed with the following command.

composer --version

Local installation

To install in your project folder or in other folder you need to download the composer.phar file using this stable version link or Linux and macOS users can use console command wget https://getcomposer.org/composer-stable.phar -O composer.phar.

Then run Composer by just executing the command in the console:

php composer.phar

In Linux or macOS operating systems you can run it by:

./composer.phar

only after adding execute permissions to the composer.phar file by the chmod command:

chmod +x composer.phar

If you use VCS don’t forget to make the composer.phar file as untracked in a VCS ignore file to prevent accidental commit Composer file to VCS.

Global installation on Linux or macOS

To install it globally on Linux or macOS (without Homebrew) you should download it and add execute permissions as described above in the Local installation section.

Then move the composer.phar file to the folder which is in the PATH variable. Usually, it's /usr/local/bin:

sudo mv composer.phar /usr/local/bin/composer

but some macOS versions don’t have this folder and you need to create it by the command mkdir /usr/local/bin.

To sum it all up, you can install Composer globally just using three bash commands:

wget https://getcomposer.org/composer-stable.phar -O composer.phar
chmow +x composer.phar
sudo mv composer.phar /usr/local/bin/composer

Then you can run Composer in any folders:

composer

Global installation on Windows

To install Composer globally on the Windows machine you can do it by the installer, just download Composer-Setup.exe and run then.

This installer also setup PATH variable in your system to global access to Composer then you can run it:

composer

Don’t forget to log out then log in for your Windows user to apply PATH changes otherwise you’ll get the error like 'composer' is not recognized:

Error: 'composer' is not recognized

Conclusion

As you see Composer installation is a simple process. I hope this guide helped you, let me know in the comments!

--

--

Vitaliy Dotsenko
Legacybeta

I like coding, open-source software and hi-tech 🚀