How to Use ‘sudo update-alternatives –config php’ to Manage PHP Versions

Introduction to PHP Version Management

Managing multiple versions of PHP on a single system can be challenging for developers and system administrators. The ‘sudo update-alternatives –config php’ command is a powerful tool that simplifies this process by allowing users to switch between different installed PHP versions easily.

Understanding the ‘update-alternatives’ Command

The ‘update-alternatives’ command is a Debian-based system utility that helps manage symbolic links for default commands. This tool is particularly useful for handling multiple versions of software, such as PHP, ensuring that the appropriate version is used across your projects.

Using ‘sudo update-alternatives –config php’

To start managing your PHP versions, open your terminal and execute the following command:

sudo update-alternatives --config php

This command will display a list of all the PHP versions installed on your system. Each version will be associated with a selection number. You can choose the desired version by entering the corresponding number. For example:

There are 2 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/php7.4 74 auto mode
1 /usr/bin/php7.4 74 manual mode
2 /usr/bin/php8.0 80 manual mode

Conclusion

Managing PHP versions on your system is made simple with the ‘sudo update-alternatives –config php’ command. By following the steps outlined above, you can easily switch between different PHP versions to suit your development and testing needs. This flexibility ensures that your projects can leverage the correct PHP version without any hassle.

Leave a Reply

Your email address will not be published. Required fields are marked *