1

what is snap?

snap is a brand-new package management method. It is similar to a container with all the files and libraries of an application, and each application is completely independent. So the advantage of using the snap package is that it solves the problem of dependencies between applications and makes it easier to manage between applications. But the problem with this is that it takes up more disk space.
The installation package extension of snap is .snap , which is similar to a container, which contains all the files and libraries needed by an application (snap package contains a private root file system, which contains dependent packages). They are installed into separate directories; the applications are isolated from each other. There are many benefits to using snap, firstly it solves the problem of package dependencies; secondly, it also makes the application easier to manage.
There are not many applications that support snap now, and snap packages are generally installed in the /snap directory.

How to install snap?

In the ubuntu system, snap is provided by the system by default, but not in the official image of the debian system in the docker container. Most linux distributions do not come with snap, so additional installation is required. For steps to install snap on rpm distributions such as centos, please refer to this article https://www.linuxidc.com/Linux/2020-03/162485.htm

Configure apt's Aliyuan

The default ubuntu apt software source of is too slow to access in China, which often leads to installation failures. Here, the sed command is used to replace the apt software source and replace it with Ali's apt software source.
sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
sed -i s@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
apt-get clean
apt-get update

install snap

sudo apt-get install snapd

Install jdk using snap

sudo snap install openjdk

Add JDK to environment variables

Careful students may have found that using snap to install openjdk, it is still impossible to run java-related commands in the command, this is because we have not configured jdk into the environment variables.

Enter openjdk in the command to get the openjdk configuration file address

openjdk
// 例如输出
// /var/snap/openjdk/common/openjdk.env

Use the cat command output to view the contents of the configuration file

cat /var/snap/openjdk/common/openjdk.env

For example, what I output here is as follows:

# Source this file for OpenJDK environment variables and aliases
export JAVA_HOME=/snap/openjdk/714/jdk
export MANPATH=/snap/openjdk/714/jdk/man:
alias java='openjdk.java'
alias javac='openjdk.javac'
alias javadoc='openjdk.javadoc'
alias jar='openjdk.jar'
alias jarsigner='openjdk.jarsigner'
alias jlink='openjdk.jlink'
alias jpackage='openjdk.jpackage'

Copy the output of the configuration file, open the /etc/profile file with vim or other editor (note that sudo is sometimes required), and add the copied configuration content to the end of the /etc/profile file.

refresh environment variables

source /etc/profile

At this point, you can view the java version information in the terminal. If it can be output, the configuration is successful. (Sometimes you may need to restart your computer)

java --version

// 输出样例
// openjdk 17.0.2 2022-01-18
// OpenJDK Runtime Environment (build 17.0.2+8-snap)
// OpenJDK 64-Bit Server VM (build 17.0.2+8-snap, mixed mode, sharing)

而井
851 声望1.8k 粉丝