How to correctly upgrade the software when building Linux (CentOS) with Vagrant ~ Using the example of upgrading from Python 2.7 to Python 3.6 ~

What is PATH?

Not limited to Linux, it is not necessary to write the full path when executing a command because the information of that path is stored in PATH. For example, when shutting down Linux, you can write shutdown -h now instead of / usr / sbin / shutdown -h now because / usr / sbin / is registered in your PATH. is.

How to check PATH

Do the following:

echo $PATH

Execution result: image.png

In my case, this is because I messed with it. You can register as many PATHs as you like, and they are separated by :.

What to do when the same software with different versions is installed

For example, CentOS 7 has python 2.7 by default. If you run python --version, you will get the version information. Now suppose you hit the following new command and use Red Hut Enterprise Linux to drop python 3.6.

sudo yum -y install centos-release-scl;
sudo yum -y install rh-python36;
sudo scl enable rh-python36 bash;

When I execute python --version after this, I see python 3.6, but when I reload the path by Vagrant operation etc., it returns to the original. This is because python 3.6 dropped by Red Hut Enterprise Linux drops to / opt / rh / rh-python36 / root / bin / instead of going to / usr / bin. Unless this / opt / rh / rh-python36 / root / bin / is registered in the PATH and python2.7 in / usr / bin is removed, the version of python cannot be upgraded cleanly. .. By the way, the path of python referenced by Linux can be found by the following command.

which python

This which, not just python, tells you the actual path of the command that Linux is referencing.

When removing an older version of a program, such as python2.7, it is better to rename it with the mv command and set it aside, rather than deleting it with the rm command. Below is the command when taking the Python example.

sudo mv /usr/bin/python2.7 /usr/bin/python2.7_old

Linux can now evacuate Python 2.7.

How to change PATH

I think there are several, but my favorite is to use the source command to import a file called ~ / .bash_profile. There is PATH information in ~ / .bash_profile, and PATH registration is done by executing source ~ / .bash_profile. Note the person doing this in a shell script, but you should specify in the script where this ~ is. This is because the ~ part is different between the root user and the general user (see video). vagrant_root_homedirectory.gif

When I put a shell in Vagrantfile and executed it, I didn't know which direction ~ was facing (when I did vagrant provision, the executing user was vagrant, but ~ was` / root / It seemed like I was looking at the side), so I specified it.

As a result, I read the PATH with the following command.

#/home/vagrant/.bash_Set PATH information in profile
echo "export PATH="/opt/rh/rh-python36/root/bin:/usr/bin:/usr/sbin"" >> /home/vagrant/.bash_profile;
#Register PATH information
source /home/vagrant/.bash_profile;


If you keep the above steps, you can upgrade any software without any problems. I was able to upgrade sqlite 3.2 to sqlite 3.29 with the same approach.


Recommended Posts

How to correctly upgrade the software when building Linux (CentOS) with Vagrant ~ Using the example of upgrading from Python 2.7 to Python 3.6 ~
How to know the number of GPUs from python ~ Notes on using multiprocessing with pytorch ~
When using PyQtGraph with Python Pyside, pay attention to the order of import
About the handling of ZIP files including Japanese files when upgrading from Python2 to Python3
From the initial state of CentOS8 to running php python perl ruby with nginx
How to get into the python development environment with Vagrant
How to scrape stock prices of individual stocks from the Nikkei newspaper website with Python
How to get followers and followers from python using the Mastodon API
How to avoid duplication of data when inputting from Python to SQLite.
[Python] Explains how to use the format function with an example
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
How to deal with the problem that the current directory moves when Python is executed from Atom
How to crop the lower right part of the image with Python OpenCV
[Python] Explains how to use the range function with a concrete example
[Introduction to Python] How to sort the contents of a list efficiently with list sort
How to deal with SSL error when connecting to S3 with boto of Python
How to deal with the problem that build fails when CI / CD of Python Function with AWS Amplify
How to operate Linux from the console
How to install python3 with docker centos
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
Note: How to get the last day of the month with python (added the first day of the month)
[Python Tips] How to retrieve multiple keys with the maximum value from the dictionary
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
How to deal with SessionNotCreatedException when using Selenium
How to operate Linux from the outside Procedure
How to handle Linux commands well from Python
How to specify attributes with Mock of python
Try to find the probability that it is a multiple of 3 and not a multiple of 5 when one is removed from a card with natural numbers 1 to 100 using Ruby and Python.
How to return to the command from the state where you can not enter interactive mode with python of git bash
How to identify the element with the smallest number of characters in a Python list?
Extract images and tables from pdf with python to reduce the burden of reporting
How to pass arguments when invoking python script from blender on the command line
A memo of misunderstanding when trying to load the entire self-made module with Python3
How to count the number of occurrences of each element in the list in Python with weight
The 15th offline real-time I tried to solve the problem of how to write with python
[Python] How to remove duplicate values from the list
The wall of changing the Django service from Python 2.7 to Python 3
Learn Nim with Python (from the beginning of the year).
How to scrape image data from flickr with python
[Introduction to Python] How to iterate with the range function?
[Python] How to specify the download location with youtube-dl
How to exit when using Python in Terminal (Mac)
[Python] Summary of how to specify the color of the figure
About the --enable-shared option when building Python on Linux
[Introduction to Python] How to stop the loop using break?
[Python] How to rewrite the table style with python-pptx [python-pptx]
Study from the beginning of Python Hour8: Using packages
ODBC access to SQL Server from Linux with Python
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
How to write offline real time I tried to solve the problem of F02 with Python
The basics of building an in-house server for Linux (CentOS 8.1, openSUSE 15.1, Ubuntu 20.04)! File server with Samba
How to create an instance of a particular class from dict using __new__ () in python
[Cyberduck] How to exchange files on Linux (CentOS7) started by VirtualBox with mac using GUI
How to quickly count the frequency of appearance of characters from a character string in Python?
How to deal with the terminal getting into the pipenv environment without permission when using pipenv with vscode
How to get the information of organizations, Cost Explorer of another AWS account with Lambda (python)
How to write when you want to put a number after the group number to be replaced with a regular expression in re.sub of Python
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
I tried using the Python library from Ruby with PyCall
Offline real-time how to write Python implementation example of E14