# 進行第一次系統升級、調校及安裝基礎套件

##### **1 基本升級**

<div class="pointer-container" id="bkmrk-%C2%A0"><div class="pointer anim is-page-editable"><svg class="svg-icon" data-icon="link" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg><div class="input-group inline block"> <button class="button outline icon" data-clipboard-target="#pointer-url" title="複製連結" type="button"><svg class="svg-icon" data-icon="copy" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg></button></div><svg class="svg-icon" data-icon="edit" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg></div></div>在安裝完基礎系統後，需進行基本的升級工作，建議使用安裝過程式的**一般**用戶名稱登入，並使用 sudo 指令進行系統更新作業。

```shell
$ sudo apt update
```

一樣第一次會請你輸入 sudo 的密碼：

```shell
[sudo] password for ossii:
```

輸入正確的密碼後，就會以 Root 身份執行 apt update 的工作了，接下來會出現類似於以下的訊息。

```shell
Hit:1 http://tw.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://tw.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://tw.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://tw.archive.ubuntu.com/ubuntu focal-security InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
41 packages can be upgraded. Run 'apt list --upgradable' to see them.
```

接下來請執行以下指令：

```shell
$ sudo apt upgrade
```

然後接著會出現要升級的套件資訊，如下所示：

```shell
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  libfwupdplugin1
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  libfwupdplugin5 libmbim-glib4 libmbim-proxy libmm-glib0 libqmi-glib5 libqmi-proxy modemmanager
  usb-modeswitch usb-modeswitch-data
The following packages will be upgraded:
  alsa-ucm-conf apt apt-utils bolt command-not-found fwupd fwupd-signed isc-dhcp-client
  isc-dhcp-common kmod landscape-common libapt-pkg6.0 libc-bin libc6 libfwupd2 libjcat1 libkeyutils1
  libkmod2 libnetplan0 libnss-systemd libpam-systemd libsystemd0 libudev1 locales login netplan.io
  open-vm-tools passwd python3-commandnotfound python3-distupgrade sbsigntool snapd sosreport
  systemd systemd-sysv systemd-timesyncd ubuntu-advantage-tools ubuntu-release-upgrader-core udev
  unattended-upgrades update-notifier-common
41 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 59.8 MB of archives.
After this operation, 17.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] 按下 Y 鍵開始下載更新
```

第一次更新完請重新開機，指令如下：

```shell
$ sudo reboot
```

##### **2 安裝基礎套件**

<div class="pointer-container" id="bkmrk-%C2%A0-0"><div class="pointer anim is-page-editable"><svg class="svg-icon" data-icon="link" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg><div class="input-group inline block"> <button class="button outline icon" data-clipboard-target="#pointer-url" title="複製連結" type="button"><svg class="svg-icon" data-icon="copy" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg></button></div><svg class="svg-icon" data-icon="edit" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg></div></div>基本上會建議安裝以下常用的基本套件，這樣在之後的管理工作上會比較簡單，這份清單會隨著時間更新，列表及說明如下：

<table border="3" cellspacing="1" id="bkmrk-%E9%A0%85%E6%AC%A1-%E5%A5%97%E4%BB%B6%E5%90%8D%E7%A8%B1-%E8%AA%AA%E6%98%8E-1-vim-%E6%8F%90%E4%BE%9B%E6%9B%B4" style="border-collapse: collapse; width: 100%; height: 158.984px; border-color: #000000; border-style: inset;"><tbody><tr style="height: 29.7969px;"><td class="align-center" style="width: 6.30408%; height: 29.7969px;">項次</td><td class="align-center" style="width: 26.4452%; height: 29.7969px;">套件名稱</td><td class="align-center" style="width: 67.2507%; height: 29.7969px;">說明</td></tr><tr style="height: 29.7969px;"><td class="align-center" style="width: 6.30408%; height: 29.7969px;">1</td><td class="align-center" style="width: 26.4452%; height: 29.7969px;">vim</td><td style="width: 67.2507%; height: 29.7969px;">提供更多 vi 編輯器效果的延伸套件，讓你編輯純文字文件時不再只是單調的畫面。</td></tr><tr style="height: 29.7969px;"><td class="align-center" style="width: 6.30408%; height: 29.7969px;">2</td><td class="align-center" style="width: 26.4452%; height: 29.7969px;">wget</td><td style="width: 67.2507%; height: 29.7969px;">下載網路連結檔案的工具，常常會在安裝其它非 RPM Base 的工具中用到。</td></tr><tr style="height: 29.7969px;"><td class="align-center" style="width: 6.30408%; height: 29.7969px;">3</td><td class="align-center" style="width: 26.4452%; height: 29.7969px;">net-tools</td><td style="width: 67.2507%; height: 29.7969px;">基本網路查詢工具，在確認網路或是服務狀態時會常常用上。</td></tr><tr style="height: 10px;"><td class="align-center" style="width: 6.30408%; height: 10px;">4</td><td class="align-center" style="width: 26.4452%; height: 10px;">unzip</td><td style="width: 67.2507%; height: 10px;">解壓縮工具。</td></tr></tbody></table>

安裝指令如下：

```shell
$ sudo apt install vim wget net-tools unzip
```

一樣在輸入 Root 密碼後按下「Y」鍵，系統即會自動安裝完成。

##### **3 基本調校工作**

<div class="pointer-container" id="bkmrk-%C2%A0-1"><div class="pointer anim is-page-editable"><svg class="svg-icon" data-icon="link" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg><div class="input-group inline block"> <button class="button outline icon" data-clipboard-target="#pointer-url" title="複製連結" type="button"><svg class="svg-icon" data-icon="copy" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg></button></div><svg class="svg-icon" data-icon="edit" role="presentation" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"></svg></div></div>- **變更密碼**


如果您想要變更 root 密碼，可以使用「passwd」指令，變更 root 密碼的操作方式如下：

```shell
$ sudo passwd root
New password:
Retype new password:
passwd: password updated successfully
```

- **變更系統網路 IP**

先查詢看看目前的 IP 及網卡資訊為何，我們可以使用 ifconfig 指令：

```
$ ifconfig
ens18: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.78  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::448a:95ff:fe70:da59  prefixlen 64  scopeid 0x20<link>
        ether 46:8a:95:70:da:59  txqueuelen 1000  (Ethernet)
        RX packets 16374  bytes 13711868 (13.7 MB)
        RX errors 0  dropped 3  overruns 0  frame 0
        TX packets 4024  bytes 308208 (308.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
```

所以會看到，網路卡是 ens18，IP 則是 192.168.3.78，如果我們要變更網路資訊的話，請用 vim 指令([**<span style="color: #e03e2d;">vim 指令教學</span>**](https://blog.techbridge.cc/2020/04/06/how-to-use-vim-as-an-editor-tutorial/))編輯網路設定檔，本例如下：

```shell
$ sudo vim /etc/netplan/00-installer-config.yaml
```

內容如下：

> \# This is the network config written by 'subiquity'  
> network:  
>  ethernets:  
>  ens18:  
>  addresses:  
> <span style="color: #e03e2d;"> **- 192.168.3.79/24**</span>  
> **<span style="color: #e03e2d;"> gateway4: 192.168.3.1</span>**  
>  nameservers:  
>  addresses:  
> **<span style="color: #e03e2d;"> - 8.8.8.8</span>**  
>  search:  
>  - ossii.com.tw  
>  version: 2

上面紅色的部份就請依照實際的網路環境變更即可，存檔之後執行以下的指令即可重新取得新的 IP 資訊。

```shell
$ sudo netplan apply
```

這個時候若是透過 SSH 連線的話，應該會斷線，請重新以新的 IP(本例為：192.168.3.79) 連入，資訊如下：

```shell
$ ifconfig
ens18: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.79  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::448a:95ff:fe70:da59  prefixlen 64  scopeid 0x20<link>
        ether 46:8a:95:70:da:59  txqueuelen 1000  (Ethernet)
        RX packets 126577  bytes 24996107 (24.9 MB)
        RX errors 0  dropped 11  overruns 0  frame 0
        TX packets 4511  bytes 353668 (353.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
```

- 調整系統時間

Ubuntu 20.04 預設的時區資訊可能是錯誤的，請先使用 date 的指令來查詢，結果如下：

```shell
$ date
Tue 26 Jul 2022 06:22:34 AM UTC
```

若要調整時區，請使用 timedatectl 指令來設定，若是 Asia/Taipei 時區，請使用下以下指令：

```shell
$ sudo timedatectl set-timezone Asia/Taipei
[sudo] password for ossii:
ossii@ubuntu-test-server2:~$ date
Tue 26 Jul 2022 02:25:02 PM CST
```

這樣子就完成了時間的調校工作，如果想要列出所有時區的名稱，可以使用以下指令：

```shell
$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
...
...
```

如此就完成了 Ubuntu 20.04 基本的主機調整工作啦～