Install Composer on Raspberry Pi

Composer is a dependency management tool for PHP that allows to specify libraries on which project depends on. Composer manages libraries installation and update per-project (the default) or globally.

This tutorial shows how to install Composer on Raspberry Pi.

Connect to Raspberry Pi via SSH and make sure that you have installed PHP:

php --version

Use wget tool to download Composer installer.

wget -O composer-setup.php https://getcomposer.org/installer

Run the following command to install Composer globally as a system-wide command:

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

Composer was placed under /usr/local/bin directory and will be available for all users as composer command. Now we can check Composer version:

composer --version

After installation, Composer installer is unnecessary and we can remove it:

rm -rf composer-setup.php

We can use the following command to update Composer to the latest version:

sudo composer self-update

If you want to downgrade Composer to the latest 1.x version, execute the following command:

sudo composer self-update --1

Run the following command if you want to upgrade Composer to the latest 2.x version:

sudo composer self-update --2

It is also possible to update Composer to a specific version:

sudo composer self-update 1.10.19
sudo composer self-update 2.0.8

If you decided to remove Composer, you need to remove Composer command itself and all related directories.

sudo rm -rf /usr/local/bin/composer
rm -rf ~/.cache/composer
rm -rf ~/.local/share/composer
rm -rf ~/.config/composer

Leave a Comment

Your email address will not be published. Required fields are marked *