1. Introduction to environment variable files
Environment variables in Linux include system level and user level. System-level environment variables are system variables that every user who logs in to the system must read, while user-level environment variables are the Environment variables loaded when the user uses the system.
So the files that manage environment variables are also divided into system level and user level. Here is a relatively clear file introduction found on the Internet
1. System level:
(1)/etc/profile: This file is the user login , the first file used by the operating system to customize the user environment and applies to every user who logs into the system. This file is generally called the /etc/bash.bashrc file.
/etc/bash.bashrc: System-level bashrc file.
(2)/etc/environment: The second file used by the operating system when logging in. The system sets the environment variables of the environment file before reading your own profile.
2. User level (these files are in the home directory):
(1) ~/.profile: Each user can use this file to enter shell information dedicated to their own use. When the user logs in, the file only executes Once! By default, he sets some environment variables and executes the user's .bashrc file. This is the recommended place to put your personal settings
(2) ~/.bashrc: This file contains bash information specific to your bash shell. This file is read when logging in and every time you open a new shell. It is not recommended to put it here, because every time a shell is opened, this file will be read once, which will definitely affect the efficiency.
~/.bash_profile or ~./bash_login: The author is not cited here. It will be mentioned below.
~/.pam_environment: User-level environment variable setting file. I have not tested it. I don’t know if it works.
Through the above file introduction, we can understand what files need to be modified when we need to set environment variables. To take effect for all users, we need to set system-level environment variables. On the contrary, user-level files need to be modified (preferably the .profile file, for the reasons mentioned above).
In addition, I am using Ubuntu10.04. When I was looking for information to set user-level environment variables, some information said that I need to modify the ~.bash_profile file, but there is no such file in the ubuntu10.04 system. After searching, I found the description of this file on the ubuntu official website [2]:
~/.bash_profile or ~./bash_login - If one of these files exist, bash executes it rather then "~/.profile" when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default.
It should mean that when this file exists , when logging in to the shell, the ./bash_profile file will be read instead of the .profile file. I think the purpose of this file is the same as that of the .profile file. When the information you are looking for requires you to modify the .bash_profile file, but you do not have the file, you can also modify the .profile to complete the implementation.
[1]http://cab402.appspot.com/2010/05/1/UbuntuEnvironmentVariablesSet.html
[2]https://help.ubuntu.com/community/EnvironmentVariables
2. Actual configuration of environment variables
1. Configure java environment variables
(1) First download the jdk installation file on the official website. What I downloaded is: jdk-7u5-linux-i586.tar.gz. Of course, you can also download the .bin format file. However, this kind of file is different from the tar format file introduced in this article in terms of decompression, and will not be introduced in detail here;
(2) Decompress the file, the decompressed file name is: jdk1.7.0_05; Copy to a file directory. What I put is: /home/stopit/software directory, so the current jdk path is /home/stopit/software/jdk1.7.0_05, here /home/stopit/software/jdk1.7.0_05 Replace with xxx;
(3) According to several Linux environment variable files introduced above, we choose the profile file to write our environment variables; use the suodo gedit /etc/proifle command to open the file and enter the following command:
#Modify java operating environment
export JAVA_HOME="xxx"
export PATH="$PATH:$JAVA_HOME/bin"
export JRE_HOME="$JAVA_HOME/jre"
export CLASSPATH=".:$JAVA_HOME/lib:$JRE_HOME /lib"
(4) After the modification is completed, use the source /etc/profile command to update;
(5) The following steps are more important, because openjdk is pre-installed in many Linux systems, so even if the above steps are performed After these settings, the system default is not what we want to set; if we want to actually use our own jdk, we still need the following steps:
sudo update-alternatives --install /usr/bin/java java xxx/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac xxx/bin/javac 300
(The 300 here is just for identification, it has no meaning, it is just used in the next step)
sudo update-alternatives --config java
Executing this step will list all installed java on the system, and then Select, that is, choose the one with the last 300
sudo update-alternatives --config javac
Same as above
Note: Some articles say that just use the following statement:
sudo update-alternatives –config java, the author Haven't tried it yet!
(6) Done, use the java -version command to view our java environment variables, the following content is displayed:
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) Server VM (build 23.1-b03, mixed mode)
2. Configure tomcat environment variables
(1) Download the tomcat software package from the official website.
http://tomcat.apache.org/
Click on the download version on the left. I chose tomcat6.x. You can choose to install it according to your actual situation. Click on the hyperlink and select Binary Distributions. tar.gz (pgp, md5) compressed package, download it
(2) After downloading to the local, decompress it
#tar zxvf apach-tomcat-6.0.16.tar.gz
#mv apach-tomcat- 6.0.16 /usr/local
(3) Configure the tomcat environment (you need to install jdk)
sudo geidt /etc/profile
Enter the following content
export TOMCAT_HOME=xx
xx Same as above, for you Tomcat installation path
Save and exit
(4)# source /etc/profile //Let the current configuration take effect immediately
(5) Start the tomcat server and run the following content
sudo xx/bin/ startup.sh
Note: (you cannot manually double-click startup.sh under the file to execute). I don’t know if it is possible for the time being. The following content will appear on my computer:
$ sudo /opt/tomcat/bin/shutdown.sh
——Get MySQL’s JDBC, enter http: //dev.mysql.com/get/Downloads/Connector-J/mysql- in the address bar of the Firefox browser connector-java-3.1.10.tar.gz/from/http: //mysql.cbn.net.id/ to get the software.
——Install JDBC
$tar -zxvf mysql-connector-java-3.1.10.tar.gz
$sudo cp mysql-connector-java-3.1.10/mysql-connector-java-3.1.10-bin* .jar /usr/lib/j2sdk1.5-sun/lib
——Configure the Tomcat port
The Tomcat that comes with Ubuntu opens port 8180, which is neither conventional nor conducive to use. We can make some simple modifications to let Tomcat use other ports for services. In Terminal, enter
sudo gedit /usr/share/tomcat5/conf/server.xml
Find
And replace 8180 with the required port. Under normal circumstances, it can be replaced with 80 or 8080. If it is set to 80, you can access the Tomcat page by directly entering http://localhost in the browser. Restart Tomcat to take effect.
——Set the Tomcat administrator account
Tomcat user account information is saved in the tomcat-users.xml file, run
sudo gedit /usr/share/tomcat5/conf/tomcat-users.xml
in < ;/tomcat-users> Add a line before the label
Save and close. Re-run tomcat to enter the user name and password and log in to the Tomcat management page.
——Install the latest version of Tomcat
We will next introduce downloading and using the latest version 5.5.17 of Tomcat software directly from the Apache Tomcat homepage. This method is convenient and fast and does not affect the stability of the system.
After downloading the zip or tar.gz package in the Binary->Core category from tomcat’s official download page http://tomcat.apache.org/download-55.cgi
, decompress it locally and use the newly generated The directory is renamed to tomcat for ease of use. Move this folder to a path PATH/. Refer to the above steps for setting environment variables and port settings, and you're done! Directly run
PS. At the beginning, I used apt-get to install tomcat5.5, but it always failed to install successfully. During shutdown, a java exception appeared. In the end, there was really no way. Use
sudo apt-get remove tomcat5.5
Uninstalled it. Download and install it again without apt-get
For more articles related to environment variable files and configuration in Linux, please pay attention to the PHP Chinese website!