Java full stack Programmer's 02:ubuntu under the Java environment installation, configuration, testing

Source: Internet
Author: User
Tags coding standards tmp folder

After the above, we are in the hands of Ubuntu can only be counted as an internet machine, nothing can do, this article we will toss it for the development machine.

Here, we assume that you are a beginner to the Linux system, so this article will talk a little bit, the master will go left.

1. Installation

First we determine if the Ubuntu system we installed is already installed in the Java environment.

Enter the terminal, type the command Su, enter the root mode (can also dispense with this step, of course), typing command java-version. If you see this interface, it shows that the Java environment is not installed,

Ps: We've talked about how to delete an old JDK in our course, and it's a little bit out of the way.

Then, let's go to Oracle's website and download jdk,https://www.oracle.com/technetwork/java/javase/downloads/index.html.

To avoid being told that I was too conservative, this time I went back to the radical state of 10 years ago and downloaded the latest version of Jdk10. If we are going to configure this machine to be used to develop production code, I recommend that you roll back at least one major version.

I downloaded it by default using Fireforx, and after downloading it, we can find it in the archive manager. Of course, for the novice, it must be curious about its location throughout the Ubuntu file system.

We open the File manager (compared to "My Computer" under Windows) and the default is to go to the home directory of the current account (which is a bit like the user directory of Windows that you used to use). And this current account, generally not the root user, so we see the interface is probably the following look.

However, the default download path for Firefox is in the root root directory of the TMP directory. Then the question comes, and you will find that in the above interface, we are less likely to find the root TMP.

Go to the root directory

So how do we find it?

One way to do this is in the interface above, and in the following sequence

In this way to get to the root directory, we only have browse permissions.

Another way is to type the command in the terminal: sudo nautilus, then enter the password and click "File system root" in the file system that pops up. Then we finally got to the root directory and found the TMP folder.

In the TMP directory, there is a folder called MOZILLA_YOURNAME0, click in, we just downloaded the JDK file package.

Next, where do we install the JDK?

If it is windows, we can create a folder, or install the package, we will be installed by default to program files. But under normal circumstances, we will tidy up our own folders, then, under Ubuntu, we also need to understand the contents of the directory or what to do, and according to the conventional, we should place the JDK we are about to install.

Linux Directory Introduction

In the Antidote Linux directory, we still have to start with the introduction of the root directory. Why is the root directory so important to us that we obediently stay in the current user's home directory is not very good?

Good is good, but we are developers, we need to toss, for example, I installed the Windows system, the first thing is to activate the administrator, and then switch to the user login status.

In the root directory, there are some of these main directories:

1:bin, binary executable file for system

2:sbin, only root can access the executable file

3:ETC, System configuration file

4:USR (not user Oh, is the UNIX shared resources), very important, it can be understood as c:/windows/,

/usr/lib understood as C:/windows/system32,

/usr/local: User-level program directory, can be understood as C:/progrem files/. User-compiled software is installed by default in this directory.

/USR/SRC: System-level source directory.

/USR/LOCAL/SRC: User-level source directory.

Of course, the above only gives general advice, and does not necessarily have to follow this very dogmatic placement of documents.

5:dev (not develop, device), storing equipment files, drivers, etc.

6:root,root User's home directory (different from root directory)

7:boot, files that need to be used when the system starts

8:mnt (mount), root install temporary file mount point

9:lib, placing the system running and the Lib library on which the third-party program runs

10:tmp, place various temporary files

11:var, placing files that need to change data at run time

12:opt:opt has an optional meaning, is also the user-level program directory, can be understood as d:/software. For example, in the next idea we want to install, we're going to put it in this directory.

Through the above understanding, we know that the installation software is best placed under USR, so we create a java1002 folder under the directory.

However, if we go directly to the root directory through the desktop system, we will find that the "new folder" is grayed out. At this point, we will have access to the desktop system via sudo nautilus to be able to create folders.

Once created, cut the JDK package into a new directory and extract it.

If the command is used to extract the word, it is:

TAR–XVF jdk-10.0.2-linux-x64.tar.gz–c/usr/local/java1002

Under Ubuntu, unzip is installed. Now, we need to configure several environment variables for Java.

2. Configuration

Students accustomed to using Windows must have experienced this problem, that is, when we install the software, we often ask whether only the current user is allowed to use. In fact, there are similar problems under Ubuntu. In general, the Ubuntu configuration we can configure in two places,

Global configuration file:

/etc/profile

/etc/bashrc

Current User profile:

~/.bash_profile

~/.bashrc

What's the difference between these 4 places?

The difference between profile and BASHRC files

/etc/profile: Mainly used to set the system environment variables, such as $path, is valid for all users.

/ETC/BASHRC: Sets the system-bash shell-related parameters, which are valid for all users. The user runs the Bash command, using the parameters right here.

~/.bash_profile: Set environment variable, function similar to/etc/profile, valid for current user.

~/.BASHRC: function Similar to/ETC/BASHRC, valid for the current user.

Note that the ~ refers to the current user's home directory. If the current user is root, then ~ is/root/, otherwise it is/home/yourname/.

It is also important to note that

~/.bash_profile is only valid when the user is logged on, and ~/.BASHRC is run Non-login, that is, the file is read as long as the command line is run as that user.

Java environment variable Configuration

From the above description, we know that the Java environment variables are best configured in/etc/profile. Again, we want sudo nautilus to find the file, and then add it at the end

Note that this is for experienced students to say. In Jdk10, there is no JRE directory, so in the configuration we do not need to configure the JRE information.

Save, close.

Ps: can also be used in terminal via command: sudo vim/etc/profile Open Text editor, press <Insert> to enter edit mode, fill in the contents, press <Esc> to exit edit mode, then press ":" and then enter "wq!" Save and exit.

Typing commands in the terminal,

Source Profile

Alternatively, we can restart Ubuntu and let the configuration take effect.

Now, let's hit the command java-version, and when you see this interface, it means we're successful.

3. Testing

Next, let's go back to the current user's home directory and we'll create a javacode directory where we're going to place the first Java program.

First, open the text editor and enter the code:

Then, to the terminal, go to the directory where the files are located,

Javac Hellozuikc.java

If the command executes successfully, a Hellozuikc.class file is found and then executed:

Java HELLOZUIKC

Everything is done as follows:

Ornate Split Line (the following is the ad time)

===========================================================

1: Most courses javaee+ Internet distributed new technology class, you want to learn a different Java development technology, to http://www.zuikc.com look at it;

2: Most curriculum Minjia in the cloud community and Java coding Standards Creator Ali Orphan brings the Java theme: https://yq.aliyun.com/promotion/651

For more technical articles and class information, please join

QQ Group:

Java full stack Programmer's 02:ubuntu under the Java environment installation, configuration, testing

Related Article

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.