Linux中安装java和python环境

Linux中安装java和python环境_第1张图片

一、安装jdk

下载上传jdk-8u281-linux-x64.tar.gz 到指文件夹。

1.下载二进制安装包jdk-8u281-linux-x64.tar.gz

2.上传安装包

3.解压

tar xzvf jdk-8u281-linux-x64.tar.gz -C /data/environment

4.配置JDK环境变量

编辑环境变量

vim /etc/profile

添加Java环境变量

export JAVA_HOME=/data/environment/jdk1.8.0_281
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}

强制保存并退出

#让profile立即生效:

source /etc/profile

5.查看版本

java
java -version

二、安装go语言环境

1.下载二进制安装包go1.14.15.linux-amd64.tar.gz

2.上传安装包

3.解压

tar -zxvf go1.14.15.linux-amd64.tar.gz -C /data/environment

4.添加环境变量

vim /etc/profile
// 在最后一行添加
export GOROOT=/data/environment/go
export PATH=$PATH:$GOROOT/bin
// wq保存退出后source一下
source /etc/profil

5.查看版本

go
go version

三、安装python环境

1.下载二进制安装包Python-3.9.4.tgz

2.上传安装包

[root@ncayu618 software]# wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz
--2021-04-18 21:50:33--  https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz
正在解析主机 www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:1a::223
正在连接 www.python.org (www.python.org)|151.101.228.223|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:25411523 (24M) [application/octet-stream]
正在保存至: “Python-3.9.4.tgz”

100%[==================================================================================================================================================>] 25,411,523   162KB/s 用时 2m 28s 

2021-04-18 21:53:01 (168 KB/s) - 已保存 “Python-3.9.4.tgz” [25411523/25411523])

3.安装依赖环境

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

4.安装Python3

安装在/data/environment/(具体安装位置看个人喜好)

#1.安装gcc   

yum install gcc

#2.python3.7版本之后需要一个新的包libffi-devel

yum install libffi-devel -y

#3.进入python文件夹,生成编译脚本(指定安装目录)

 cd /data/environment/Python-3.9.4

./configure --prefix=/data/environment/Python-3.9.4

#4.编译:

make

#5.编译成功后,编译安装:

make install

# 6.检查python3.7的编译器:/data/environment/Python-3.9.4/bin/python3.9

./python3.9

然后就出现这样的界面
[root@ncayu618 bin]# ./python3.9
Python 3.9.4 (default, Apr 19 2021, 09:30:23) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

5.建立Python3和pip3的软链:

ln -s /data/environment/Python-3.9.4/bin/python3.9 /usr/bin/python3

ln -s /data/environment/Python-3.9.4/bin/pip3 /usr/bin/pip3

6.将/data/environment/Python-3.9.4/bin加入PATH

1.编辑/etc/profile

vim /etc/profile

2.按“I”,然后贴上下面内容:

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/data/environment/Python-3.9.4/bin

export PATH

3.按ESC,输入:wq回车退出

4.修改完记得执行行下面的命令,让上一步的修改生效:

source ~/.bash_profile

7.检查Python3及pip3是否正常可用:

python3 -V

pip3 -V

[root@ncayu618 bin]# pip3 -V
pip 20.2.3 from /data/environment/Python-3.9.4/lib/python3.9/site-packages/pip (python 3.9)
[root@ncayu618 bin]# python3 -V
Python 3.9.4

写在最后

Linux中自带了python环境,python2.7(这个是给yum使用的);我第一次安装python3.9,我直接把2.7的环境卸载了,然后yum就废了。所以改个软连接就好

你可能感兴趣的:(运维学习笔记,linux,java,python)