Ubuntu18.04 Java开发环境搭建教程
Ubuntu 18.04 教程
1.Ubuntu 18.04 更换国内源
国内常用的ubuntu源:中科大源,阿里源,清华源,网易源
- 清华源
1 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse 2 deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse 3 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse 4 deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse 5 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse 6 deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse 7 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse 8 deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse 9 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse 10 deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
- 阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
- 网易源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
- 中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
此处以清华源为例:
- 按住Ctrl+alt+t打开命令行
- 输入:
sudo gedit /etc/apt/sources.list
- 输入密码
- 将上面的源复制到文件中,并覆盖,选择一处即可
- 更新
1 sudo apt-get update 2 sudo apt-get upgrate
- 此处可能会报错,显示无法获得锁,注销一下再执行即可
2.Ubuntu 18.04 Java开发环境搭建
- 安装jdk1.8
- 去官网下载1.8版本的jdk,例如我用的1.8.0_171
- 为避免到其他位置解压缩麻烦,建议下载后,直接在下载文件夹选中文件,右键提取到此处
- 在opt目录下新建一个environment目录,再创建一个Java子目录:
sudo mkdir environment sudo mkdir java
- 移动解压缩后的jdk目录到java目录下:
sudo mv jdk1.8.0_171 /opt/environment/java/
- 配置环境变量:
sudo gedit ~/.bashrc
- 然后将下面三行粘贴到文件最底部,将位置修改为自己的
1 export JAVA_HOME=/opt/environment/jdk1.8.0_171 2 export CLASSPATH=.:${JAVA_HOME}/lib 3 export PATH=${JAVA_HOME}/bin:$PATH
- 使用java -version测试是否安装完成
- 安装MySQL57
- 此处选择后台下载方式,首先复制下列语句到终端:
wget -b https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -o mysql-download.log
- 可以使用 下列语句查看下载进度:
tail -f mysql-download.log
- 解压缩,并移动到指定目录,如:
sudo mv mysql-5.7.22-linux-glibc2.12-x86_64 /opt/
- 创建软链接:
sudo ln -s /opt/mysql-5.7.22-linux-glibc2.12-x86_64/ /opt/mysql
- 安装依赖:
1 sudo apt-cache search libaio 2 sudo apt-get install libaio1
- 建立用户组:
1 sudo groupadd mysql 2 sudo useradd -r -g mysql -s /bin/false mysql
- 创建服务端配置文件:
1 cat > /opt/mysql/etc/my.cnf <<CNF 2 [mysqld] 3 basedir=/opt/mysql 4 datadir=/data/mysql 5 port=3306 6 socket=/data/mysql/mysql.sock 7 max_connections=260 8 pid-file=/data/mysql/mysql.pid 9 log-error=/data/mysql/error.log 10 CNF
- 初始化数据目录:
1 sudo /opt/mysql/bin/mysqld ---defaults-file=/opt/mysql/etc/my.cnf --user=mysql –initialize-in 2 SQL> alter user root@localhost identified by '1';
- 启动musql:
sudo /opt/mysql/bin/mysqld --defaults-file=/opt/mysql/etc/my.cnf --user=mysql 2>&1 &
- 创建客户端配置文件:
1 cat >~/.my.cnf <<EOF 2 [client]user=root 3 password=1 4 #在 /opt/mysql/etc/my.cnf 中有配置。用于本机进程通信 5 socket=/data/mysql/mysql.sock 6 EOF
- 注:因为我本人安装MySQL的时候网上并没有系统的关于ubuntu18.04的教程,所以当时安装的不是很顺利,最后没办法,把压缩包解压后,一个一个点击安装的,此处教程转自博客园网友ChaseForFuture,原文地址
- 安装eclipse
- 安装eclipse相对简单,到eclipse官网下载最新的eclipse 4.7.3a的安装包,然后解压缩
- 移动到/opt 目录下即可,但是每次使用都需要进入eclipse的bin目录太麻烦,建议手工配置桌面快捷方式
- 步骤如下:
- 打开终端,输入sudo gedit /usr/share/applications/eclipse.desktop
- 将下面的这段代码复制进去:
1 [Desktop Entry] 2 3 Encoding=UTF-8 4 5 Name=Eclipse 6 7 Comment=Eclipse 8 9 #将下面这行改成自己的安装位置,最后一个eclipse不要擅自去掉,linux下eclipse的可运行文件没有后缀名 10 11 Exec=/opt/software/eclipse-jee-oxygen-3a-linux-gtk-x86_64/eclipse/eclipse 12 13 Icon=/opt/software/eclipse-jee-oxygen-3a-linux-gtk-x86_64/eclipse/icon.xpm 14 15 Terminal=false 16 17 StartupNotify=true 18 19 Type=Application 20 21 Categories=Application;Development
- 打开终端,输入sudo gedit /usr/share/applications/eclipse.desktop
- 安装eclipse相对简单,到eclipse官网下载最新的eclipse 4.7.3a的安装包,然后解压缩
- 安装idea
- 安装idea教程和上面安装eclipse差不多
- 如果需要破解的话,到http://idea.lanyus.com/下载破解补丁,然后打开安装目录下bin目录,粘贴
- 找到idea64.vmoptions和idea.vmoptions,使用gedit或者vim打开,在最底下加上如下代码:
-javaagent:/opt/software/ideaIU-2018.1.2/idea-IU-181.4668.68/bin/JetbrainsCrack-2.7-release-str.jar
- 冒号后面的地址指向破解补丁对应的地址
- 创建快捷方式或者使用sh idea.sh 命令打开idea,选择第二种验证方式,验证代码可以随意输入
- 创建快捷方式和上面步骤相同,也略有不同,如下:
1 [Desktop Entry] 2 Encoding=UTF-8 3 Name=IntelliJ IDEA 4 Comment=IntelliJ IDEA 5 #因为idea在linux下的可运行文件是.sh方式,所以配置稍有不同 6 Exec=sh /opt/software/ideaIU-2018.1.2/idea-IU-181.4668.68/bin/idea.sh 7 Icon=/opt/software/ideaIU-2018.1.2/idea-IU-181.4668.68/bin/idea.png 8 Terminal=false 9 Type=Application 10 Categories=Developer; 11 Name[zh_CN]=IDEA
- 安装maven
- 解压缩并移动到自定义的目录
- 配置环境变量,如上配置jdk,使用:
sudo gedit ~/.bashrc
- 添加如下代码:
1 export M2_HOME=/opt/environment/maven/apache-maven-3.5.3-bin/apache-maven-3.5.3 2 export PATH=${M2_HOME}/bin:$PATH
- 使用mvn -v 验证安装是否成功
- 安装git
- 至于git,安装很简单:
sudo apt-get install git
- 使用方式我就懒得放了,写了一下午,脖子酸
- 至于git,安装很简单:
3.Ubuntu18.04 搜狗输入法安装教程
ubuntu18.04,因为依赖原因造成搜狗输入法安装失败,或者安装后无法启动等问题。
- 首先,到搜狗官网下载最新的deb安装文件
- 然后使用命令行安装依赖:sudo apt install libfcitx-qt0
- 在文件下载目录创建一个新的临时文件夹:mkdir temp
- 接着将deb安装文件解压到temp文件夹中:dpkg-deb -R sogoupinyin_2.2.0.0102_amd64.deb temp/
- 使用gedit编辑器编辑 temp/DEBIAN/control :gedit temp/DEBIAN/control
- 找到fcitx-libs-qt (>= 4.2.7),将之替换成libfcitx-qt0 (>= 1:4.2.9.6-1)
- 在temp同级目录下创建新的build文件夹
- 重新封包:dpkg-deb -b temp/ build/
- 双击deb安装文件进行安装或者使用 dekg -i sogoupinyin_2.2.0.0102_amd64.deb
- 解决依赖问题:sudo apt install –fix-broken
- 将键盘输入法系统设置位fcitx,重启系统,将输入法设置成zh