In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
A few days ago, we discussed how to switch between different PHP versions. In that article, we used the update-alternatives command to switch from one PHP version to another PHP version. That is, the update-alternatives command sets the default version of PHP used by system-wide system wide to the version we want. In popular terms, you can set the version of the program from the system-wide via the update-alternatives command. If you want to be able to dynamically set different versions of programs in different directories, how do you do that? In this case, the alt tool can make a difference. Alt is a command-line tool that allows you to switch between different versions of the same program in a Unix-like system. The tool is easy to use and is free and open source software written in Rust.
Installation
Installing the alt tool is easy.
Run the following command to install alt on the Linux host:
$curl-sL https://github.com/dotboris/alt/raw/master/install.sh | bash-s
Next, add the shims directory to your PATH environment variable, depending on the Shell you use.
For Bash:
$echo 'export PATH= "$HOME/.local/alt/shims:$PATH' > > ~ / .bashrc$ source ~ / .bashrc
For Zsh:
$echo 'export PATH= "$HOME/.local/alt/shims:$PATH' > > ~ / .zshrc$ source ~ / .zshrc
For Fish:
$echo 'set-x PATH "$HOME/.local/alt/shims" $PATH' > > ~ / .config/fish/config.fish
Now alt has been installed!
Use the alt tool to switch different versions of the same program in the Linux system
As I mentioned earlier, alt only affects the current directory. In other words, when you make a version switch, it only takes effect in the current directory, not system-wide.
The following is an example. I installed two versions of PHP on my Ubuntu system, PHP 5.6 and PHP 7.2, and included some PHP applications in the myproject directory.
First, check the system-wide default version of PHP with the command:
$php-v
Sample output:
As shown in the screenshot, the default PHP version on my system is PHP 7.2.
Then, I will go to the myproject directory where the PHP application is placed.
$cd myproject
Scan for available PHP versions using the following command:
$alt scan php
Sample output:
As you can see, I have two PHP versions, PHP 5.6 and PHP 7.2. Press the key to select the currently available version. After selecting all available versions, you can see the cross cross mark shown in the figure. Use the up and down arrow keys to move between versions, click enter to save the changes.
Let's run the command and select the version of PHP we want to use in the myproject directory:
$alt use php
I want to use the PHP5.6 version, so I (use the arrow keys) to select that version and click enter.
Now, you can use PHP version 5.6 in the / home/sk/myproject directory.
Let's check whether PHP version 5.6 is used by default in the myproject directory:
$php-v
Sample output:
PHP version 5.6 will always be used as long as you don't set it to another version. Is that clear? Fine! Please note that we only use PHP version 5.6 in this directory. On a system-wide basis (LCTT), PHP 7.2 is still the default version. Let's check it out. Please look at the picture below.
As you can see from the screenshot above, I have two versions of PHP: in the myproject directory, the version used is PHP 5.6; in other directories outside myproject, the version used is PHP 7.2.
In the same way, you can set the version of the program you want for each directory. I use PHP here for illustrative purposes only, but the method applies to any software you intend to use, such as NodeJS, etc.
The following is a sample video of NodeJS.
If you want to test your application under different package versions, then alt is a good choice for you.
PS: let's look at the switching between different java versions of linux.
Recently, because you often use jdk7 and jdk8, you need to switch jdk manually.
Terminal input after installing jdk7 and jdk8 at the same time
$sudo update-alternatives-config java$ sudo update-alternatives-config javac
Summary
The above is the editor to introduce to you how to switch between different versions of the same program in Linux, I hope to help you, if you have any questions, please leave me a message, the editor will reply to you in time. Thank you very much for your support to the website!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.