Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Simple Bash Script for Installing Composer on Ubuntu Locally (current user) and Globally (all users).

Installation

Install composer locally (current user only):

wget -O - https://gist.github.com/EmpireWorld/1dd5f59566e186907f99dc16badc382a/raw/install-composer-local.sh | bash

Install composer globally (all users):

wget -O - https://gist.github.com/EmpireWorld/1dd5f59566e186907f99dc16badc382a/raw/install-composer-global.sh | bash

Made with ❤️ by Bayat

#!/bin/bash
########################
# Written by Hasan Bayat
# Installs composer for all users.
# License MIT @ Bayat
########################
# Check if composer currently installed
if hash composer; then
echo "Composer Already Installed"
echo "You can find it at $(type -p composer)"
exit
fi
# Update package index
sudo apt update
# Make sure php is installed
sudo apt install php php-cli
# Download latest composer snapshot and run it by php
sudo wget https://getcomposer.org/composer.phar
# Move composer to /bin/composer
sudo mv composer.phar /bin/composer
echo "Composer Installed Globally Successfully"
echo "Composer Installed at $(type -p composer)"
echo "You can always find it by calling `type -p composer`"
#!/bin/bash
########################
# Written by Hasan Bayat
# Installs composer for current user only.
# License MIT @ Bayat
########################
# Check if composer currently installed
if hash composer; then
echo "Composer Already Installed"
echo "You can find it at $(type -p composer)"
exit
fi
# Update package index
sudo apt update
# Make sure php is installed
sudo apt install php php-cli
# Download latest composer snapshot and run it by php
sudo wget https://getcomposer.org/composer.phar
# Move composer to /usr/local/bin/composer
sudo mv composer.phar /usr/local/bin/composer
echo "Composer Installed Locally Successfully"
echo "Composer Installed at $(type -p composer)"
echo "You can always find it by calling `type -p composer`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.