Ubuntu environment variable error prevents normal login

Original link: https://www.cnblogs.com/austinspark-jessylu/p/7987142.html

 1. Problems arise

 

When configuring the JDK, I modified the contents of the /etc/profile file according to the practice in an article I found. On the basis of keeping the original content unchanged, roughly the following content has been added:

export JAVA_HOME=....

export PATH=....

However, when restarting and trying to log into X windows again, an error occurs. There is no response after entering the password, and it still stays on the Login interface. If you can't log in through the graphical interface, you have to try Ctrl+Alt+F1 to enter the CLI.

 

Second, the positioning problem

 

Entering the command line interface, I don't know the cause of the problem for the time being. The difference from usual is that after logging into the command line system and returning the welcome message, many errors are reported, as shown in the figure:

 

Solve the error of Ubuntu environment variable and cause it to fail to log in normally - windflyer - Shao Yuru's Blog

 

It is natural to first stop at the longest lines:

The command could not be located because '/usr/bin:/bin' is not included in the PATH environment variable.

Meaning: command not found because '/usr/bin:/bin' is not included in the environment variable PATH.

This is where the problem arises: the environment variable PATH is wrong. Assuming that the PATH has been manipulated when the /etc/profile file is modified, the easiest way to solve the problem is to restore /etc/profile to the state before the modification.

 

After reading the error message, I plan to clear the screen for the next step, enter: clear. The same error is reported:

Command 'clear' is available in '/usr/bin/clear'

The command could not be located because '/usr/bin' in not included in the PATH environment variable.

clear:command not found

Tried several other commonly used commands: ls, vim, cat, etc., the reason for the error is the same, all point to the environment variable PATH.

 

3. The role of PATH

 

Linux has a PATH. Those who have configured JDK under Windows must have noticed that Windows also has a PATH. What is the purpose of this PATH? Here's an explanation:

       When we enter a command on the command line (terminal or tty1~6 under Linux, cmd under Windows), we actually execute a program. For example, using the ls command actually runs the ls program, whose function is to list the contents of the current directory. However, by default, when searching for programs to run, it only looks in the current directory. And the commands we usually use can be executed no matter which directory they are in. Is there a copy of these commands in each directory? Of course not, this waste of space is too serious.

     The common practice adopted by operating systems now is to specify the location where the commands are stored through the PATH variable. Once a command is used, the program corresponding to the command is searched according to the order in which the directories are specified in the PATH. So under normal circumstances, use echo $PATH to view the contents of the environment variable PATH as follows:

A semicolon ":" represents a delimiter that separates each directory.

Due to the wrong PATH, when I use the command, the system cannot normally look for the directory where the command is stored, so it will prompt: Command not found.

 

Fourth, the solution

 

It is very humane that the system will prompt us to store the correct location of the command to be used, such as the prompt when using clear: Command 'clear' is available in '/usr/bin/clear'. The clear command is stored in the '/usr/bin' directory.

To edit /etc/profile, the command normally used is: sudo vim /etc/profile

Now, the system can't find the sudo command, nor the vim command, so it has to manually specify their absolute paths. Both sudo and vim are stored in the '/usr/bin' directory, so the absolute paths of sudo and vim are: /usr/bin/sudo /usr/bin/vim

So to edit /etc/profile the command to use would be: /usr/bin/sudo /usr/bin/vim /etc/profile

You only need to delete the content you added before (it is best to modify it to be correct, if you are not sure, you should at least restore it to the original state), then save and restart the system.

 Solve the error of Ubuntu environment variable and cause it to fail to log in normally - windflyer - Shao Yuru's Blog

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324672842&siteId=291194637