In this post, I will tell you about a very useful tool for web developers. Especially those who use PHP as the main language for their applications. This is Composer which is a very light dependency manager and easy to use. So, in this post, you will learn how to install Composer on Linux.
What is Composer?
Composer is a tool for dependency management in PHP. So, it allows you to declare the libraries your project depends on and it will manage (install/update) them for you. This way we will not have to worry about installing those libraries.
To do this, Composer is strongly inspired by NPM and Ruby’s bundler. In other words, it is not a package manager like APT or Yum, because it does not install specific applications globally but only libraries.
On the same Composer website, we are given the following example to show the usefulness of the tool.
First, suppose:
- You have a project that depends on a number of libraries.
- Some of those libraries depend on other libraries.
Composer:
- Enables you to declare the libraries you depend on.
- Finds out which versions of which packages can and need to be installed, and installs them (meaning it downloads them into your project).
So, let us start to install Composer.
Install Composer on Linux
The installation of Composer is quite simple. Because of the impressive tool, it is almost a gift. First, you need to install PHP.
:~$ sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip
Next, show the PHP version.
:~$ php -v PHP 7.0.33-0+deb9u3 (cli) (built: Mar 8 2019 10:01:24) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.33-0+deb9u3, Copyright (c) 1999-2017, by Zend Technologies
Composer requires at least PHP 5.4. However, many Linux distributions in their repositories have recent versions. For example, Ubuntu has version 7.2 and Debian 7.0. In both cases, they are sufficient versions for installation.
Next, you need to install a tool to download the installer using the terminal. Of course, you can do it from the Composer website, but in the terminal, it’s faster.
:~$ sudo apt install curl
Then, install Composer using this command:
:~$ curl -sS https://getcomposer.org/installer | php
If you want to install Composer globally, to make it a system command, perform these commands:
:~$ sudo mv composer.phar /usr/local/bin/composer :~$ sudo chmod +x /usr/local/bin/composer :~$ source ~/.bashrc
And show the Composer version.
:~$ composer -v
And that’s it.
Conclusion
For web developers, it is important to have tools that help create applications. In this sense, Composer is presented to us as a vital dependency manager for our projects.
So, please share this post with your friends.
Gracias, me ha funcionado tu guía. En Linux Mint 20.1