make a certain software version the default in ubuntu
Solution 1
I think the best way to do this on Ubuntu is like that:
sudo update-alternatives --set php /usr/bin/php5.6
You may change the version according to your needs.
Solution 2
There are a million things you can do instead of changing your $PATH.
One is to define an alias in your /home/YOUR_NAME/.bashrc file,
alias myphp=' /path/to/my/favorite/php '
Another one is to rename the version of php that you do not want, and to transform /usr/bin/php in a symbolic link to the version you wish to use:
sudo mv /usr/bin/php /usr/bin/php_5.3.10
sudo ln -s /path/to/php/you/want /usr/bin/php
Or you may use the Debian alternatives system. First, you install a php alternative,
sudo update-alternatives --install "/usr/bin/php" "php" "/pathto/your/favorite/php" 1
then you control that everything's fine by means of
sudo update-alternatives --display php
And much, much more.
Solution 3
sudo update-alternatives --config php
chanHXC
Updated on September 18, 2022Comments
-
chanHXC over 1 year
I currently have 2 version of php installed on ubuntu 12.04.
one for php 5.3 installed using apt-get while the other one is installed with xampp with php 5.5
When i execute these commands:
> which php /usr/bin/php > php --version PHP 5.3.10-1ubuntu3.8 with Suhosin-Patch (cli) (built: Sep 4 2013 20:05:42) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethan >echo $PATH /home/chanhxc/bin /usr/lib/lightdm/lightdm /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /opt/lampp/bin /home/chanhxc/pear/bin /home/chanhxc/.composer/vendor/bin /opt/lampp/bin /home/chanhxc/bin /usr/lib/lightdm/lightdm /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /home/chanhxc/bin /usr/lib/lightdm/lightdm /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /opt/lampp/bin /home/chanhxc/pear/bin /home/chanhxc/.composer/vendor/bin /opt/lampp/bin
How do i make php 5.5 the default version to be run?
Btw, my default shell is zsh. here's the line in my .zshrc
export PATH=$PATH:/home/chanhxc/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games # xampp, pear, composer export PATH=$PATH:/opt/lampp/bin:/home/chanhxc/pear/bin:/home/chanhxc/.composer/vendor/bin:/opt/lampp/bin
Update
If i'm opting for the update-alternatives option. Here's what i currently have.
>update-alternatives --query php Link: php Status: auto Best: /usr/bin/php5 Value: /usr/bin/php5 Alternative: /usr/bin/php5 Priority: 50 Slaves: php.1.gz /usr/share/man/man1/php5.1.gz
-
chanHXC over 10 yearsthanks for the suggestion. but what's the best way there. i actually have an alias as phplatest with php 5.5 version. would soft linking php in /usr/bin/php makes the other version in xampp be default?
-
chanHXC over 10 yearsbtw, what exactly does an update-alternative command do?
-
MariusMatutiae over 10 yearsKeeps tab of which programs, all providing the same service, you prefer to use. Like having Chrome, Chromium, Firefox, Iceweasel on the same pc, which one should open when you click on alink in an e-mail? The one update-alternatives has indicated as the master.
-
chanHXC over 10 yearsok thanks. but why do i get unknown argument `php'. when executing update-alternatives
-
MariusMatutiae over 10 years@chanHXC That's because I made an error in the syntax. I have updated my post, it should now work. Remember to move the existing php to /usr/bin/php_old
-
Dave Drager over 7 yearsI agree that this is the best way to do this. It updates the link in /usr/bin/php to the correct version. In Ubuntu 16 you can install php5.6 and php7.0 and have them running at the same time - which is nice, but sometimes you want to update the default.
-
Rolando Isidoro almost 6 yearsThis might be more user-friendly as it allows the user to interactively select which of the available alternatives to choose from.