# CentOS下手动安装JDK,Python环境和界面切换

## CentOS7图形界面与命令行界面切换

1. 在图形界面使用 `Ctrl+Alt+F2` 切换到dos界面
2. dos界面 `Ctrl+Alt+F2` 切换回图形界面
3. 在命令上,输入 `init 3` 命令切换到dos界面
4. 输入 `init 5` 命令切换到图形界面

**如果想系统默认以某种方式启动,使用systemd创建符号链接指向默认运行级别。** 修改方法为: 首先删除已经存在的符号链接:

```
rm /etc/systemd/system/default.target
```

默认级别转换为3(文本模式):

```
ln -sf /lib/systemd/system/multi-user.target /etc/systemdsystem/default.target
```

或者默认级别转换为5(图形模式):

```
ln -sf /lib/systemd/system/graphical.target /etc/systemdsystem/default.target
```

重启:

```
reboot
```

## Centos7手动安装JDK以及环境配置

云服务器的SSH登录(建议Xshell),安装必要程序后

依次运行命令:

```
mkdir /usr/java
wget https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_linux-x64_bin.tar.gz
tar zxvf jdk-13.0.2_linux-x64_bin.tar.gz
rm -f jdk-13.0.2_linux-x64_bin.tar.gz
vim /etc/profile # 或者 vi /etc/profile
```

末尾添加并保存

```
export JAVA_HOME=/usr/java/jdk1.8.0_152
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
```

最后使修改生效

```
source /etc/profile
```

测试命令

```
java -version
```

## CentOS7 下 Python3 的编译安装

配置好yum源: 安装好前置依赖

```
yum -y install gcc python-setuptools.noarch bash-compleetion-extras.noarch
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
```

或者

```
yum install gcc python-setuptools.noarch bash-compleetion-extras.noarch \
            zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel \
            openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel \
            tk tk-devel gcc-c++ make imake cmake automake glibc glibc-devel glib2 libxml glib2-devel \
            libxml2 libxml2-devel libmcrypt libmcrypt-devel postgresql-devel
```

### 使用源码进行编译安装

官网下载源码包

```
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
```

解压

```
xz Python-3.8.1.tar.gz
tar -xvzf Python-3.8.1.tgz
```

进入目录:配置安装目录,如果没有目标目录需要提前创建

```
./configure --prefix=/usr/local/python3 --enable-optimizations --enable-shared --enable-optimizations　
# 不配置也可以,直接./configure命令

# --prefix：指定安装路径
# --enable-shared：禁用/启用构建共享python库
# --enable-optimizations：启用昂贵,稳定的优化（PGO等）。默认情况下禁用。
# 安装时善用 ./configure --help 这个功能..
```

编译,安装

```
make && make install
```

修改Python共享库

```
vim /etc/ld.so.conf.d/python3.conf
```

在/etc/ld.so.conf.d/python3.conf文件中添加以下内容:

```
/usr/local/python3/lib/
```

刷新动态链


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://3385706034.gitbook.io/note/centos-jdk-py.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
