# <center>樹莓派上安裝Ubuntu</center>
###### <center>GOGO!</center>
---
### **<u>前情提要</u>**
 我使用的是Raspberry Pi 4,安裝 Ubuntu20.04 server版。
 **需要準備的東西:**
  ● Raspberry Pi 4
  ● micro SD卡 / micro SD讀卡機
  ● 外接螢幕/鍵盤/(滑鼠)
  ● micro HDMI轉接線
---
### **<u>安裝步驟</u>**
1. 首先,在自己的電腦上,GOOGLE搜尋 **`Install Ubuntu on a Raspberry Pi`** 選擇Ubuntu官網或點以下[連結](https://ubuntu.com/download/raspberry-pi)。
2. 下載映像檔。我要安裝的是Ubuntu 20.04,目前官網只提供該版本的server版。如果你是想安裝Desktop版本,也可以先下載server版,之後可以透過終端指令安裝。下載並解壓縮後,得到映像檔,圖示如下。
<div style="text-align: center">
<img src="https://i.imgur.com/bzRE7uX.png"/>
</div>
3. 燒錄映像檔至SD卡。燒錄的方法有很多種,這裡介紹我使用的工具,[Rufus](https://rufus.ie/en/) (只需下載Portable版本,不需安裝,即可使用)。打開Rufus後,紅色圈圈處選擇映像檔,按下執行,完成後選擇離開。
<div style="text-align: center">
<img src="https://i.imgur.com/Z6QzLrU.png"/>
</div>
</br>
:::info
小提醒:燒錄不是像一般我們將檔案儲存到隨身碟一樣,請不要將映像檔直接拉入資料夾中。
:::
4. 將SD卡插回樹莓派上,已經完成一半了!
5. <font color="red">注意:開機前請先將外接螢幕的HDMI線及鍵鼠的USB插上,全部確定好後, **最後再開啟電源** 。</font>
6. 樹莓派成功開機後,會顯示以下登入畫面。預設的帳號密碼皆為ubuntu,輸入後它會要求更改新密碼。
<div style="text-align: center">
<img src="https://i.imgur.com/ksUEoYp.jpg"/>
</div>
7. 成功登入後,先設定網路。
(1)確認網卡名稱,我的是wlan0。
```cmake=
sudo lshw
```
(2)移至目錄/etc/netplan底下。
```cmake=
cd /etc/netplan/
```
(3)打開文件 50-cloud-init.yaml。
```cmake=
sudo nano 50-cloud-init.yaml
```
(4)修改 50-cloud-init.yaml文件內容成以下。
```cmake=
network:
version: 2
ethernets:
eth0:
optional: true
dhcp4: true
wifis:
wlan0:
optional: true
access-points:
"your_SSID_name":
password: "your_network_password"
dhcp4: true
```
(5)儲存文件退出後,輸入以下指令debug,並apply。
確認剛剛的文件有沒有error。
```cmake=
sudo netplan -debug try
```
如果出現error,以下指令可以進一步看到error message。
```cmake=
sudo netplan --debug generate
```
確認沒問題後,apply這個檔案。
```cmake=
sudo netplan --debug apply
```
8. 重新啟動ubuntu
```cmake=
sudo reboot
```
9. update & upgrade
```cmake=
sudo apt-get update
```
```cmake=
sudo apt-get upgrade
```
10. Ubuntu server版安裝完成!
11. 如果你要安裝的是Desktop版,請繼續執行下面的指令。
```cmake=
sudo apt-get install ubuntu-desktop
```
(會等上一陣子...)
```cmake=
sudo reboot
```
Ubuntu Desktop版安裝完成!
---
<h5 style="text-align:right">寫於2022/2/16</h5>