NeuronVM bread crumb arrow icon Docs bread crumb arrow icon How to Install Composer on Ubuntu 20.04

How to Install Composer on Ubuntu 20.04 (Real Experience)

How to Install Composer on Ubuntu 20.04
Eileen.B
10m
0 comments
Print
2025/11/05

If you are a PHP developer, you are probably familiar with Composer. Composer is a package management tool for PHP that makes it very easy to install and update libraries and dependencies for your projects. Sometimes, when PHP projects get complex or you need multiple libraries, manually managing dependencies can be time-consuming and error-prone. I first encountered the problem of installing libraries when I was working on a Laravel project. npm and traditional package management methods didn’t work until I came across Composer. Since then, I have always installed Composer first before starting any PHP project. In this article, you will learn step by step how to install Composer on Ubuntu 20.04, and also provide some practical tips from my personal experience for professional use.

Steps to install Composer on Ubuntu 20.04

Step 1: Prepare the prerequisites

First of all, make sure your system is up to date and that PHP and the necessary tools are installed:

sudo apt-get update
sudo apt install php7.4 php-cli unzip

Ubuntu update command

Step 2: Download Composer installation script

Download the composer-setup.php script to /tmp:

curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php

Step 3: Verifying the installation file

You can easily get the Composer security signature and verify the script by the following command:

HASH=`curl -sS https://composer.github.io/installer.sig`
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

If the output is Installer verified, you can continue.

Step 4: Install Composer Globally

Run the script to install Composer in /usr/local/bin:

sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

Install Composer command

Step 5: Verify Composer Installation

To ensure proper installation, run the following command:

composer

If installed correctly, the output will include the Composer version and command options.

Composer version output

Step 6: Install Composer locally (optional)

If you want Composer to be installed for just one project or one user, run the following command in the desired directory:

curl -sS https://getcomposer.org/installer | php
php composer.phar

Step 7: Using Composer in a PHP Project

Create a project and add packages, for example, Monolog:

mkdir monolog
cd monolog
composer requires monolog/monolog

Now the composer.json file is created and the dependencies are registered. To update a specific package:

composer update vendor/package

My Experience with Composer

The first time I used Composer, I was in the middle of a Laravel project that was full of libraries and dependencies. Every time I tried to install a package, something would break or the versions wouldn’t read together. A friend of mine said to me, “Have you installed Composer?” I sat down that night and quickly installed it, It was like a lock was unlocked! Installing packages became easier, and my project became cleaner and more manageable. Since then, every time I set up a new server, the first thing I do is install Composer.

The mistake I made first

I once ran the Composer installation script directly without checking the hash of the installation file. Luckily, it didn’t cause any problems, but later I realized how dangerous it was! Now I always check the digital signature before running the installation file to make sure the file hasn’t been tampered with. It might take a minute, but it gives you peace of mind that your system’s security hasn’t been compromised.

Experience with Composer in Team Projects

When you’re working on a team, Composer is a real lifesaver. I remember we had a team project where everyone was working with a different version of PHP and a bunch of different packages. The result? A lot of errors and frustration.
Once we brought Composer in, and added the composer.lock file, everything became solid. Now, whenever we start a new project, we just run a composer install command, and that’s it, we’re all working with the exact same environment.

A simple but crucial point

A common mistake that many people (including myself ) make is to put the vendor folder inside git. Believe me, this only makes your project heavier and does not help. Just keep the composer.json and composer.lock files, these two will reinstall all the dependencies for you. Since I learned this, my life has become easier!

When Composer causes trouble

Of course, everything is not always perfect. Once on a production server, due to RAM limitations, Composer gave an Out of Memory error while installing packages. After a lot of struggle, I realized that I had to create a swap or temporarily increase the memory limit. After that experience, I always check the system resources before installing in production to avoid these errors again.

My Experience with Removing Composer

I once accidentally installed Composer locally and couldn’t figure out why the Composer command wasn’t working!
Then I realized I needed to install the global version so it could be used from anywhere. That day, I learned that installing globally is really worth it, especially when you’re working on multiple projects.

Conclusion

In my opinion, Composer is not just a tool, it is a good habit for any PHP developer. Since I learned how to work with it, my projects have become more organized, lightweight, and reliable. If you are new to PHP, installing and configuring Composer may seem difficult at first sight, but it is really just a few lines of code and will save you hours of time. Remember to always use the official Composer repository, and don’t put the vendor folder in the git, these two simple tips can save you a lot of trouble. Composer gives you a sense of order, making your projects run like a clean. I personally wouldn’t start a single project without Composer now, because I’m sure it would make everything easier and more professional. So if you haven’t used it yet, it’s time to install it and enter the real world of package management in PHP with a simple command.

Share this Post
How useful was this post for you?
0 Points from 0 votes
Frequently Asked Questions

Yes, Composer will not work without PHP. Make sure you have the correct version of PHP installed on your system before starting the installation.

In a global installation, you can run Composer in any project and path, but in a local installation, it is only active for that project. For team work, a global installation is recommended.

Eileen.B

Leave a reply

Calculate the value of (4 + 2) :

Save my name and email in this browser for the next time.

Last Comments

Show More
© Copyright 2025 NeuronVM.
Use of this Site is subject to express terms of use