Skip to content

Instantly share code, notes, and snippets.

@jhonoryza
Created February 2, 2023 08:27
Show Gist options
  • Save jhonoryza/2ced7257b23f19ef1228e13827855042 to your computer and use it in GitHub Desktop.
Save jhonoryza/2ced7257b23f19ef1228e13827855042 to your computer and use it in GitHub Desktop.
switch between php version ubuntu 20.04
# Verify PHP
php --version

# Output
PHP 8.0.13 (cli) (built: Nov 22 2021 09:50:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies
    
# PHP 7.0 
sudo update-alternatives --set php /usr/bin/php7.0
sudo update-alternatives --set phar /usr/bin/phar7.0
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.0

# PHP 8.0 
sudo update-alternatives --set php /usr/bin/php8.0
sudo update-alternatives --set phar /usr/bin/phar8.0
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.0

# Switch PHP
sudo update-alternatives --config php

# Output
There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
  0            /usr/bin/php8.0   80        auto mode
  1            /usr/bin/php7.0   70        manual mode
* 2            /usr/bin/php8.0   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/php7.0 to provide /usr/bin/php (php) in manual mode

# Switch
sudo update-alternatives --config phar

# Output
There are 2 choices for the alternative phar (providing /usr/bin/phar).

  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/phar8.0   80        auto mode
  1            /usr/bin/phar7.0   70        manual mode
* 2            /usr/bin/phar8.0   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/phar7.0 to provide /usr/bin/phar (phar) in manual mode

# Switch
sudo update-alternatives --config phar.phar

# Output
There are 2 choices for the alternative phar.phar (providing /usr/bin/phar.phar).

  Selection    Path                   Priority   Status
------------------------------------------------------------
  0            /usr/bin/phar.phar8.0   80        auto mode
  1            /usr/bin/phar.phar7.0   70        manual mode
* 2            /usr/bin/phar.phar8.0   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/phar.phar7.0 to provide /usr/bin/phar.phar (phar.phar) in manual mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment