1. Use the apt-get command to install the software and prompt E: Unable to locate package sudo error
First execute the following command:
apt-get update
Then execute the following command
sudo apt-get install
2. The console is garbled
Some servers purchased online do not have a Chinese environment installed, so that in addition to displaying system prompts in English, it will also cause Chinese garbled characters.
Today, taking the Debian system as an example, I will share the Chinese language and its environment configuration on Linux.
2.1. Install language pack
First we need to install locales
this package:
sudo apt install locales
2.2. Configure locale
Execute the following commands to configure the locale:
sudo dpkg-reconfigure locales
The configuration interface appears as follows:
Select the language environment to be installed here, usually we don’t need to choose all of them to install, just choose what we need .
There are a lot of language items, you can use the mouse wheel, PageUp
or PageDown
you can turn pages up and down, and some terminals can also use Home
and End
jump to the beginning or end, move the cursor one by one with the up and down keys, and you can find the Chinese language environment at the bottom:
Press the space to select, with an asterisk ( *
) in front of it , it will be selected. Usually, Chinese can be selected as shown in the picture zh_CN.GBK GBK
and zh_CN.UTF-8 UTF-8
these two, and finally press Enter to confirm.
Then there is the default language setting:
It is recommended to use this item in the Linux environment zh_CN.UTF-8
, press Enter to confirm, and the configuration is complete!
Then log out and log in again, or reconnect to the server, the language configuration will take effect.
2.3. The configuration still does not take effect
In most cases, after the above configuration is completed, the configuration will take effect after logging out or restarting, or after reconnecting to the server. There is no need to do the following operations. In a few cases, if it does not take effect, you can set it again through the environment variable.
The following introduces locale
the commands and provides several solutions, you can choose one according to the situation.
1) locale
Basic use of commands
First execute the following command to check the installed locales:
locale -a
View the current system language environment variable configuration:
locale
2) Temporarily change the locale
Just set the environment variable in the terminal LANG
. For example, I want to temporarily change the language environment to zh_CN.UTF-8
: .
export LANG=
zh_CN.UTF-8
This will take effect immediately, but will not work after restarting or logging in again.
3) Permanently change the current user locale
Enter the user directory and edit .bashrc
it:
cd ~ && vim .bashrc
For example, to permanently change the locale of my current user zh_CN.utf8
, .bashrc
add at the end of the file:
export LANG=zh_CN.utf8
4) Permanently change the system global locale
/etc/profile.d
Add a set-lang.sh
file (you can customize the file name) in , and write the above command to set the locale variable in it .
cd /etc/profile.d && touch set-lang.sh && chmod +x set-lang.sh
For example, to set the system locale to zh_CN.utf8
, edit set-lang.sh
the content as follows and save it:
#!/bin/bash
export LANG=zh_CN.utf8
Just restart.
It can be seen that although these methods have different scopes, they can all be set through environment variables.
3. Garbled characters in the Docker container
locales
It is still very troublesome to configure the Docker container , so it is not recommended to use the above method in the container, you only need to set the language environment variable in the container C.UTF-8
to .
If you make your own image, add it to the Dockerfile:
ENV LANG C.UTF-8
If you create a container, add the following environment variable parameters:
-e LANG=C.UTF-8
In this way, the Chinese in the container can be displayed normally!