Install the latest version of Composer on Ubuntu

If you have previously installed composer with command...

sudo apt-get install composer

...it is recommended to uninstall it first. Run the command:

sudo apt-get purge --auto-remove composer

 

Let's install the latest version now. Go to whatever directory you like and follow the instructions for Command-line installation on the official Composer website: https://getcomposer.org/download/

After you run the four commands (copy, verify, install, remove), you should end up with a single file named composer.phar.

All you have to do now is move this file to the appropriate directory with a command:

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

Try running this command anywhere...

composer -V

...and you should see the latest version of your freshly installed Composer.

 

Running composer might display this error message (where [user] is your username):

Cannot create cache directory /home/[user]/.composer/cache/repo/https---packagist.org/, or directory is not writable.
Proceeding without cache
Cannot create cache directory /home/[user]/.composer/cache/files/, or directory is not writable.
Proceeding without cache

Set the permissions with these commands (where [user] is your username):

cd ~
 sudo chown [user]:[user] .composer -R