Linux under the JDK environment variable configuration

Source: Internet
Author: User

Transfer from: http://blog.csdn.net/cheungmine/article/details/82893351 Linux directory structure

Even if this is a rookie-level problem, also often stumped the veteran. I've seen a very senior programmer install the JDK into the/home directory in an inappropriate way. Although there is not necessarily the most correct installation location, there must be an inappropriate installation location. To determine exactly where we should install the JDK, first look at the directory structure of the Unix/linux.

[Plain]View Plaincopy
  1. /bin is used to store user commands. /usr/bin is also used to store user commands.
  2. /sbin the storage location of many system commands (such as shutdown). Many system commands are also included in the/usr/sbin.
  3. /root the root user (Superuser) home directory.
  4. /mnt This directory typically includes mount points for file systems that are mounted after system boot. For example, the default CD mount point is/mnt/cdrom/. You can build a mount point for the USB drive: Mkdir/mnt/usb.
  5. /boot includes files used during boot of the kernel and other systems, up to 200M maximum. Usually I build a primary partition for/boot that is 1G.
  6. /lost+found is used by fsck to place scattered files (files with no names).
  7. /lib contains many library files that are used by programs in/bin and/sbin. The directory/usr/lib contains more library files for user programs. The/lib directory is placed under the/bin and/sbin directories required by the program's library files. Simply put,/lib is kernel-level;/usr/lib is system-level;/usr/local/lib is user-level. Only shared libraries that are used by programs in the/USR directory do not have to be placed in the/lib directory. Only the libraries required for the programs under/bin and/sbin need to be placed in the/lib directory.
  8. /dev storage device files.
  9. /etc contains many configuration files and directories.
  10. /var is used to store variable (or constantly changing) files, such as log files and printer spool files, virtual machine image files, and so on.
  11. /usr includes files and directories that are directly related to system users, such as applications and library files that support them.
  12. /proc a virtual file system (not actually stored on disk), which includes system information that is used by some programs.
  13. /INITRD is used to mount the directory of the initrd.img image file when the computer starts up and the directory to load the required device modules. Do not delete the/INITRD directory. If you delete the directory and then reboot Red Hat Linux, you will not be able to boot your computer.
  14. The temp directory of the/TMP user and program. /TMP gives all system users read and write rights.
  15. The default location for the home directory of the user.
  16. /OPT the storage directory of optional files and programs. This directory is primarily used by third-party developers to easily install and uninstall their packages.

In traditional Unix systems,/USR usually contains only the program that comes with the system when it is released, while/usr/local is the directory where the local system administrator can freely add programs. Here's a tough and strong rule: Unless you create a directory inside, the UNIX distribution must not use/usr/local.

One possible rule for Linux distributions, such as RedHat, Debian, and so on, is that the/usr directory can only be managed by the distribution's package management tool, but not to/usr/local. It is in this way that the database of the package management tool can be used to know every file in the/usr directory.

2 Configuring the Environment Java variables

There are 3 ways of configuring Java environment variables.

2.1/etc/profile

This method is recommended if your computer is used only as a development use. The shell of all users has the right to use these environment variables. Modify the/etc/profile file to execute the following statement:

[Plain]View Plaincopy
    1. $ sudo-s
    2. # echo ' Export java_home=/usr/local/java/jdk1.6.0_38 ' >>/etc/profile
    3. # echo ' Export path= $JAVA _home/bin: $JAVA _home/jre/bin: $PATH ' >>/etc/profile
    4. # echo ' Export classpath=.: $JAVA _home/lib/tools.jar: $JAVA _home/lib/dt.jar ' >>/etc/profile

Switch to any user and execute the following command, the changes to the environment variables take effect immediately:

# Source/etc/profile

Check that the Java environment variable changes are in effect:

$ java-version

2.2 ~/.profile

This is the safest way to control Java to the current user. If you need to give a user permission to use these environment variables, you only need to modify the. Profile in the home directory of their individual users, as follows:

[Plain]View Plaincopy
    1. $ CD ~/
    2. $ Echo ' Export java_home=/usr/local/java/jdk1.6.0_38 ' >>/.profile
    3. $ Echo ' Export path= $JAVA _home/bin: $JAVA _home/jre/bin: $PATH ' >>./.profile
    4. $ Echo ' Export classpath=.: $JAVA _home/lib/tools.jar: $JAVA _home/lib/dt.jar ' >>./.profile
    5. $ source./.profile
    6. $ java-version
    7. Or
    8. $ java

2.3/etc/profile.d/java.sh

This method increases the Java environment variables for all users and takes effect as soon as it is started. This is strongly not recommended unless it is on your personal development computer.

[Plain]View Plaincopy
      1. $ sudo-s
      2. # echo ' # Add Java environments to all users ' >/etc/profile.d/java.sh
      3. # chmod 755/etc/profile.d/java.sh
      4. # echo ' Export java_home=/usr/local/java/jdk1.6.0_38 ' >>/etc/profile.d/java.sh
      5. # echo ' Export path= $JAVA _home/bin: $JAVA _home/jre/bin: $PATH ' >>/etc/profile.d/java.sh
      6. # echo ' Export classpath=.: $JAVA _home/lib/tools.jar: $JAVA _home/lib/dt.jar ' >>/etc/profile.d/java.sh

Linux under the JDK environment variable configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.