從Ubuntu 16.04升級到Ubuntu 18.04之心得(持續更新)

前言

前幾天,看到Ubuntu 18.04出一段時間了,看是時機成熟了。

所以就把自己平常工作在用的ThinkPad筆電從Ubuntu 16.04升級到Ubuntu 18.04了。

當然,中途有遇到一些情況,讓升級的程序跟步驟變得有些複雜,所以這篇文章,就是在紀錄有關於升級的過程中遇到的問題提供日後大家做參考。

前置動作

當然,需要有一台Ubuntu 16.04主機,不然要怎麼升級成18.04

如果怕升級上去之後,發生一些無法預期的事情,則可以先備份,備份工具可以使用「CloneZilla」進行備份。

升級做法

先依照下面的指令去安裝所有套件的最新版本。


sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

接著按照下面的指令去檢查可以升級的版本


sudo do-release-upgrade -c

那麼,就可以找到「Ubuntu 18.04」的發行版本

接著使用下面指令開始升級


sudo do-release-upgrade

幸運的話,就會開始升級了。

不幸的話,會遇到類似下面字樣的錯誤,而我剛好有遇到下面的錯誤……


Could not calculate the upgrade, .......

這原因其實是因為在檢查的時候發現,在原來的版本中存在著很多套件衝突版本問題需要解決,使用下面的指令可以看到更詳細的套件衝突問題。


grep Broken /var/log/dist-upgrade/apt.log

那我也是遇到同樣的問題,而我嘗試把那些有衝突套件的問題從log最底下開始的套件依序一個個移除,再去使用「sudo do-release-upgrade」去測試是否可以升級。

在升級發行版本的期間,會遇到一些互動式的問題,下面的列舉如下:

  • 確定升級「libc」套件版本?
  • 版本升級上去,要用哪一個版本?
    這時會出現「使用原來版本」,「安裝新版本」與比較兩個版本差異等選項。
    第一個選項是預設的,也就是按下「enter」鍵後會做的事情,那我也是建議使用第一個選項,因為升級版本是有風險的,等之後真的有需求時再個別升級即可。

後來,就可以升級了。不過升級完成之後,會留下很多安裝但是無用的套件,所以記得要使用「sudo apt-get autoremove」來移除一些已安裝但是已經無用的套件。

升級完成之後,有可能會出現「系統有誤」或是處於不穩狀態,這就代表在升級的途中有些套件版本問題需要去解決。

但是,系統還是可以用的,等到真的要用的東西有問題,再來見招拆招的解決套件問題吧!

而且升級上去之後,有些東西會被移除,這時候只能自己手動安裝回來了。

鏡像來源設定方面,會有一些問題,比如說,設定來源不完全等。

我升級完成之後,鏡像只有設定下面兩個來源:


deb http://archive.ubuntu.com/ubuntu/ bionic main restricted
deb-src http://archive.ubuntu.com/ubuntu/ bionic main restricted

這樣是不對的,因為這樣會導致有一些套件會無法安裝到,後來我跑去抄VPS上面Ubuntu 18.04設定的鏡像,並成功了,以下是完成鏡像來源之設定:

設定檔案位置在:「/etc/apt/sources.list」


deb http://archive.ubuntu.com/ubuntu/ bionic main restricted
deb-src http://archive.ubuntu.com/ubuntu/ bionic main restricted

deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted

deb http://archive.ubuntu.com/ubuntu/ bionic universe
deb-src http://archive.ubuntu.com/ubuntu/ bionic universe
deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates universe

deb http://archive.ubuntu.com/ubuntu/ bionic multiverse
deb-src http://archive.ubuntu.com/ubuntu/ bionic multiverse
deb http://archive.ubuntu.com/ubuntu/ bionic-updates multiverse
deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates multiverse

deb http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu bionic-security main restricted
deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
deb-src http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse
deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse

設定完成之後記得執行「sudo apt-get update」去更新鏡像的來源。

PHPBrew下的PHP5.x版本

我在Ubuntu 16.04的時候,有使用PHPBrew編譯了幾個PHP 5.x版本,當升級到Ubuntu 18.04的時候,發現自己編譯的PHP 5.x不能使用了。

會出現下面的錯誤:


php: /usr/lib/x86_64-linux-gnu/libcurl.so.4: version `CURL_OPENSSL_3' not found (required by php)

查了一下原因,發現是libcurl3套件已經從18.04版本中移除了。

需要自己用下面的指令把此套件安裝回來。


sudo apt-get update

sudo apt-get install libcurl3/bionic

PCMan file manager F4快捷鍵在確切的目錄上開啟終端機

升級上去之後,會發現,在檔案管理工具上面,本來的F4快捷鍵功能就會有問題,無法正常的開啟,去發現觸發得腳本的位置在「/usr/bin/lxsession-default-terminal」,打開此檔案則會發現如下的內容:


#!/bin/sh
#
# Copyright (C) 2013 Julien Lavergne (gilir@ubuntu.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

echo "Launching terminal manager"

dbus-send --session --print-reply --dest="org.lxde.SessionManager" /org/lxde/SessionManager org.lxde.SessionManager.SessionLaunch string:"terminal_manager" string:"$PWD"> /dev/null 2>&1

exit 0

中間那一行「dbus…..」指令是有問題的。

所以我們需要找到正確啟動終端機的方法,後來發現,「lxterminal」指令可以正常的啟動終端機。而後面的再加上「–working-directory」參數與「$PWD」值就可以成功開啟當下的目錄的終端機。

所以「/usr/bin/lxsession-default-terminal」裡面的內容則需要改成:


#!/bin/sh
#
# Copyright (C) 2013 Julien Lavergne (gilir@ubuntu.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

echo "Launching terminal manager"

lxterminal --working-directory=$PWD

exit 0

參考資料