Check which version of php you are using in the console. Make sure you are running a recent version before running any composer installation scripts.
$ php --version
Navigate to the bin directory inside your home directory before running any of the installer commands.
$ cd ~/bin
You can follow the most recent instructions found at https://getcomposer.org/download/ which should recommend a series of commands to run in the console. This process will download and verify a php installer script, and execute the script to install the composer.phar file in your current directory.
Optionally rename this file to composer for easier use.
$ mv composer.phar composer
Check that the version output matches your expectations.
$ composer --version
If the above command works you are done.
This alternative method is optional. Create a reusable script that will allow you to install, upgrade or reinstall composer easily should you need to repeat the process.
The script below is a modified version of the official "How do I install Composer programmatically?" guide. Add the code below to a bash script like composer_installer.sh in your home bin directory, make that file executable and run it from your bin directory.
Note the only change we have made from the original script are the arguments to the final
php composer-setup.php
command so that it installs the file directly to your bin directory and names it composer.
#!/bin/sh
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi
php composer-setup.php --install-dir=$HOME/bin --filename=composer
RESULT=$?
rm composer-setup.php
exit $RESULT