Skip to content

Instantly share code, notes, and snippets.

@m4rc377
Last active October 29, 2024 12:39
Show Gist options
  • Select an option

  • Save m4rc377/6aebfdf1bc32d23d4ac10994e975f7a8 to your computer and use it in GitHub Desktop.

Select an option

Save m4rc377/6aebfdf1bc32d23d4ac10994e975f7a8 to your computer and use it in GitHub Desktop.
This script for add and installing multiple composer with different version and add to alternative list. tested on ubuntu 22.04 and and might work for Debian derivatives.
#!/bin/bash
clear
## Location Destination
# /usr/bin
# /usr/local/bin
dest="/usr/local/bin"
apt -y install composer
mv "$dest/composer" "$dest/composer.bak"
wget https://getcomposer.org/download/latest-1.x/composer.phar -O "$dest/composer-1.x"
wget https://getcomposer.org/download/latest-2.2.x/composer.phar -O "$dest/composer-2.2.x"
wget https://getcomposer.org/download/latest-2.x/composer.phar -O "$dest/composer-2.x"
chmod +x `ls $dest/composer-*`
## https://askubuntu.com/a/81259
# Version 1
update-alternatives --install /usr/bin/composer composer "$dest/composer-1.x" 10
# LTS
update-alternatives --install /usr/bin/composer composer "$dest/composer-2.2.x" 22
# latest
update-alternatives --install /usr/bin/composer composer "$dest/composer-2.x" 25
## For remove it
# sudo update-alternatives --remove composer /usr/local/bin/composer-1.x
# sudo update-alternatives --remove composer /usr/local/bin/composer-2.2.x
# sudo update-alternatives --remove composer /usr/local/bin/composer-2.x
# sudo rm "$dest/composer-*"
# sudo mv "$dest/composer.bak" "$dest/composer"
## if you want delete composer completely and then
# apt -y install composer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment