How to install Ubuntu 18.04 aarch64 (64bit) on RaspberryPi3

# １．Introduction
The procedure to install Ubuntu 18.04 aarch64 (64bit) on RaspberryPi3 is described below.

# ２．Environment

- Ubuntu 16.04 x86_64
- RaspberryPi3 model B+ (Ubuntu 18.04 aarch64 / Python 3.6)
- microSD card 32GB

# ３．Procedure

```console:Ubuntu_18.04_image_download
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1SyfrRqX-6KF_KxD4PBVQLT35tgI8Sf58" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1SyfrRqX-6KF_KxD4PBVQLT35tgI8Sf58" -o ubuntu-18.04.3-preinstalled-server-arm64+raspi3.img.xz
$ xz -dv ubuntu-18.04.3-preinstalled-server-arm64+raspi3.img.xz
```

```console:Download_"Etcher"_image_writing_tool
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1kH4wZiI2rFHhnDXomMJU-dgZwLw2koPQ" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1kH4wZiI2rFHhnDXomMJU-dgZwLw2koPQ" -o balenaEtcher-1.5.57-x64.AppImage
```

Insert microSD card into SD card reader/writer.

```console:Starting_"Etcher"
$ sudo ./balenaEtcher-1.5.57-x64.AppImage
```
![Screenshot 2019-09-23 14:52:07.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/57222756-f522-2a96-2fb1-b58b18fb8a53.png)
![Screenshot 2019-09-23 14:53:59.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/c82085ef-7dfe-aff2-ca0b-1a11a31143be.png)
![Screenshot 2019-09-23 14:54:04.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/7f938cf0-9a41-b85d-c903-571bfa0446bd.png)

Insert the microSD card into RaspberryPi and turn on the power.　The initial login ID and password is **`ubuntu / ubuntu`**.

```console:Package_updates
$ sudo apt-get update
$ sudo apt-get upgrade
```

```console:Check_OS_information
$ uname -a
$ cat /etc/lsb-release
```
![Screenshot 2019-09-23 15:00:18.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/e191ea9b-b778-f374-5551-b6207459229b.png)

```console:Check_resource_usage
$ df -h
$ free
```
![Screenshot 2019-09-23 15:08:44.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/c617be62-05ea-25fe-1f59-f042d7f53496.png)

```console:Change_time_zone
$ sudo timedatectl set-timezone Asia/Tokyo
```

```console:Switch_to_Japanese_keyboard
$ sudo dpkg-reconfigure keyboard-configuration
```
![Screenshot 2019-09-23 16:03:14.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/00605c3c-c36a-2c81-b6b5-b85133fd4c0d.png)
![Screenshot 2019-09-23 16:03:27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/c9b0de4b-8b5d-bb7e-8503-b52ea93234e7.png)
![Screenshot 2019-09-23 16:03:38.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/f0ff2ee3-a30f-ead1-44eb-f3818d0fcb0c.png)
![Screenshot 2019-09-23 16:03:45.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/fd2bf73c-b435-6775-1614-88db7cf828a5.png)
![Screenshot 2019-09-23 16:03:55.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/27862ddf-4b3e-86d8-db13-366b25464235.png)
![Screenshot 2019-09-23 16:04:15.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/e2d86b7a-ebee-2543-9e3e-8cfd57e6430c.png)

# ４．Optional work
## ４−１．Preparing the development environment with Python

```console:
$ sudo apt-get install wget curl git zip unzip python3-pil python3-opencv python3-pip
$ sudo -H pip3 install pip --upgrade

### numpy fast install
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1gRYmhL-mLlA-oLBvhJvzX2pj6tz0nP8y" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1gRYmhL-mLlA-oLBvhJvzX2pj6tz0nP8y" -o numpy-1.17.2-cp36-cp36m-linux_aarch64.whl
$ sudo -H pip3 install numpy-1.17.2-cp36-cp36m-linux_aarch64.whl
$ rm numpy-1.17.2-cp36-cp36m-linux_aarch64.whl
```

## ４−２．Install a lightweight Xubuntu desktop GUI environment

```console:Install_Xubuntu_(GUI)
$ sudo apt install tasksel
$ sudo tasksel install xubuntu-desktop
$ sudo reboot
```
![IMG_20190923_153711.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/5ba54fd6-0124-9a0f-413e-672c6e895746.png)

## ４−３．Expansion of swap area

```console:Setting_swap_space
$ sudo apt-get install -y dphys-swapfile
$ sudo nano /etc/dphys-swapfile

CONF_SWAPSIZE=2048
```

<kbd>Ctrl</kbd> + <kbd>O</kbd>
<kbd>Ctrl</kbd> + <kbd>X</kbd>

```console:Restart_service
$ sudo /etc/init.d/dphys-swapfile restart swapon -s
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           912M        362M         89M        7.3M        460M        527M
Swap:          2.0G          0B        2.0G
```

## ４−４．Wi-Fi settings

```console:
$ nano /etc/netplan/50-cloud-init.yaml
```

```console:
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: <MAC address>
            set-name: eth0
    wifis:
        wlan0:
            access-points:
                <SSID>:
                    password: <Passphrase>
            dhcp4: true
            dhcp6: true
```

<kbd>Ctrl</kbd> + <kbd>O</kbd>
<kbd>Ctrl</kbd> + <kbd>X</kbd>

```console:
$ sudo netplay apply
```

# ５．Reference articles

1. **[ラズパイ用のarm64版Ubuntu18.04がリリースされました。　- ラズパイノニッキ - もんごんた さん](https://raspberrypi.mongonta.com/newrelease-ubuntu-18-04-2-arm64/)**

2. **[ライブUSBやmicroSDを作る時の手順 - ガジェットズキノニッキ - もんごんた さん](https://mongonta.com/f310-howtomake-install-media-from-iso/)**