Ubuntu18.04 Java開發環境搭建教程

Ubuntu 18.04 教程html

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
    中科大源

 

此處以清華源爲例:java

    1. 按住Ctrl+alt+t打開命令行
    2. 輸入:
      sudo gedit /etc/apt/sources.list
    3. 輸入密碼
    4. 將上面的源複製到文件中,並覆蓋,選擇一處便可
    5. 更新
      1 sudo apt-get update
      2 sudo apt-get upgrate
    6. 此處可能會報錯,顯示沒法得到鎖,註銷一下再執行便可

 

2.Ubuntu 18.04 Java開發環境搭建

 

 

  1. 安裝jdk1.8
    1. 去官網下載1.8版本的jdk,例如我用的1.8.0_171
    2. 爲避免到其餘位置解壓縮麻煩,建議下載後,直接在下載文件夾選中文件,右鍵提取到此處
    3. opt目錄下新建一個environment目錄,再建立一個Java子目錄:
      sudo mkdir environment sudo mkdir java
    4. 移動解壓縮後的jdk目錄到java目錄下:
      sudo mv jdk1.8.0_171 /opt/environment/java/
    5. 配置環境變量:
      sudo gedit ~/.bashrc 
    6. 而後將下面三行粘貼到文件最底部,將位置修改成本身的
      1 export JAVA_HOME=/opt/environment/jdk1.8.0_171
      2 export CLASSPATH=.:${JAVA_HOME}/lib
      3 export PATH=${JAVA_HOME}/bin:$PATH
    7. 使用java -version測試是否安裝完成
  2. 安裝MySQL57
    1. 此處選擇後臺下載方式,首先複製下列語句到終端:
      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
    2. 可使用 下列語句查看下載進度:
      tail -f mysql-download.log
    3. 解壓縮,並移動到指定目錄,如:
      sudo mv mysql-5.7.22-linux-glibc2.12-x86_64 /opt/
    4. 建立軟連接:
      sudo ln -s /opt/mysql-5.7.22-linux-glibc2.12-x86_64/ /opt/mysql
    5. 安裝依賴:
      1 sudo apt-cache search libaio
      2 sudo apt-get install libaio1
    6. 創建用戶組:
      1 sudo groupadd mysql
      2 sudo useradd -r -g mysql -s /bin/false mysql
    7. 建立服務端配置文件:
       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
    8. 初始化數據目錄:
      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';
    9. 啓動musql:
      sudo /opt/mysql/bin/mysqld --defaults-file=/opt/mysql/etc/my.cnf --user=mysql 2>&1 &
    10. 建立客戶端配置文件:
      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
    11. 注:由於我本人安裝MySQL的時候網上並無系統的關於ubuntu18.04的教程,因此當時安裝的不是很順利,最後沒辦法,把壓縮包解壓後,一個一個點擊安裝的,此處教程轉自博客園網友ChaseForFuture原文地址
  3. 安裝eclipse
    1. 安裝eclipse相對簡單,到eclipse官網下載最新的eclipse 4.7.3a的安裝包,而後解壓縮
    2. 移動到/opt 目錄下便可,可是每次使用都須要進入eclipse的bin目錄太麻煩,建議手工配置桌面快捷方式
    3. 步驟以下:
      1. 打開終端,輸入sudo gedit /usr/share/applications/eclipse.desktop
      2. 將下面的這段代碼複製進去:
         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
        eclipse
  1. 安裝idea
    1. 安裝idea教程和上面安裝eclipse差很少
    2. 若是須要破解的話,到http://idea.lanyus.com/下載破解補丁,而後打開安裝目錄下bin目錄,粘貼
    3. 找到idea64.vmoptionsidea.vmoptions,使用gedit或者vim打開,在最底下加上以下代碼:
      -javaagent:/opt/software/ideaIU-2018.1.2/idea-IU-181.4668.68/bin/JetbrainsCrack-2.7-release-str.jar
    4. 冒號後面的地址指向破解補丁對應的地址
    5. 建立快捷方式或者使用sh idea.sh 命令打開idea,選擇第二種驗證方式,驗證代碼能夠隨意輸入
    6. 建立快捷方式和上面步驟相同,也略有不一樣,以下:
       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
      idea快捷方式
  2. 安裝maven
    1. 解壓縮並移動到自定義的目錄
    2. 配置環境變量,如上配置jdk,使用:
      sudo gedit ~/.bashrc 
    3.  添加以下代碼:
      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
    4. 使用mvn -v 驗證安裝是否成功
  3. 安裝git
    1. 至於git,安裝很簡單:
      sudo apt-get install git
    2. 使用方式我就懶得放了,寫了一下午,脖子酸  

3.Ubuntu18.04 搜狗輸入法安裝教程

ubuntu18.04,由於依賴緣由形成搜狗輸入法安裝失敗,或者安裝後沒法啓動等問題。mysql

    1. 首先,到搜狗官網下載最新的deb安裝文件
    2. 而後使用命令行安裝依賴:sudo apt install libfcitx-qt0
    3. 在文件下載目錄建立一個新的臨時文件夾:mkdir temp
    4. 接着將deb安裝文件解壓到temp文件夾中:dpkg-deb -R sogoupinyin_2.2.0.0102_amd64.deb temp/
    5. 使用gedit編輯器編輯 temp/DEBIAN/control gedit temp/DEBIAN/control
    6. 找到fcitx-libs-qt (>= 4.2.7),將之替換成libfcitx-qt0 (>= 1:4.2.9.6-1)
    7. temp同級目錄下建立新的build文件夾
    8. 從新封包:dpkg-deb -b temp/ build/
    9. 雙擊deb安裝文件進行安裝或者使用 dekg -i sogoupinyin_2.2.0.0102_amd64.deb
    10. 解決依賴問題:sudo apt install –fix-broken
    11. 將鍵盤輸入法系統設置位fcitx,重啓系統,將輸入法設置成zh
相關文章
相關標籤/搜索