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.
Do the following:
echo $PATH
Execution result:
In my case, this is because I messed with it. You can register as many PATHs as you like, and they are separated by :
.
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.
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).
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.
https://teratail.com/questions/50308 https://qiita.com/nito128/items/e91e8510c882a7f24768
Recommended Posts