---
title: "ตั้งค่า Ubuntu Server"
description: "โน๊ตนี้คือ commands ที่มักจะใช้บ่อย ๆ เมื่อต้อง setup ubuntu server (20.04, 22.04)"
canonical_url: "https://iamthana.com/blogs/2024-01-14-setup-ubuntu-server"
---

> Index of every page on this site: [llms.txt](https://iamthana.com/llms.txt)

## Introduction

รวม command ที่ต้องใช้บ่อย ๆ เมื่อมีการ Setup เครื่อง Ubuntu ใหม่ (Version 20, 22, 24)

## หมวดหมู่การตั้งค่าพื้นฐาน

### Update Packages ต่าง ๆ ที่ติดตั้งมาใน OS ให้เป็น Version ล่าสุด

```sh
sudo apt update && sudo apt upgrade -y
```

### แก้ไข timezone ให้เป็น `Asia/Bangkok`

```sh
sudo timedatectl set-timezone Asia/Bangkok
```

### ติดตั้ง Packages ที่สำคัญสำหรับการพัฒนา (Development) โดยภายใน `Build Essential` จะมีการรวมเอา Packages ที่สำคัญเอาไว้เช่น `gcc`, `c++`, `make`, `lib6-dev` และอื่น ๆ อีกมากมาย

```sh
sudo apt install build-essential
```

### แก้ไข Hostname

```sh
sudo hostnamectl set-hostname <hostname>
```

### ปิดการใช้งาน Cloud-init network

```sh
sudo nano  /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

# เอาไปใส่ในไฟล์
network: {config: disabled}
```

### ขั้นตอนการติดตั้ง docker ใน version daemon

ติดตั้ง `curl` สำหรับการเรียกใช้งาน Script

```sh
sudo apt update
sudo apt install curl -y
```

ติดตั้งโดยใช้ script จาก `get.docker.com` ซึ่งจะช่วยในการติดตั้ง docker แบบง่ายมาก ๆ

> script นี้จำเป็นต้องใช้ root หรือ sudo ในการทำงานนะครับ

```sh
cd /tmp
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
```

หากต้องการรัน docker โดยไม่ต้องรัน `sudo` นำหน้าสามารถเพิ่ม user ดังกล่าวเข้าไปใน group docker ได้ครับ

```sh
# run docker without sudo
sudo gpasswd -a $USER docker
sudo service docker restart
```

ทดสอบเรียกใช้งาน

```sh
docker --version
```

## ติดตั้ง helm

Credit: [https://helm.sh/docs/intro/install/#from-script](https://helm.sh/docs/intro/install/#from-script)

```sh
cd /tmp
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
```

## ติดตั้ง ZSH + P10k Configure เพื่อให้ใช้งาน terminal ได้ง่ายยิ่งขึ้น

```sh
sudo apt install curl wget git zsh -y

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```

ติดตั้ง plugins เพิ่มเติมโดยแนะนำเป็น `zsh-syntax-highlighting` เพื่อช่วยในการ highlight command และ `zsh-autosuggestions` ซึ่งจะเป็นการนำเอา history มาแสดงให้ขณะพิมพ์ command

```sh
# Install plugins
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
```

แก้ไข `.zshrc` file เพื่อทำการเพิ่ม plugins เข้าไป

```sh
nano ~/.zshrc

# Update plugins
plugins=(
    git
    zsh-syntax-highlighting # <- Add
    zsh-autosuggestions     # <- Add
)
```

จากนั้น reload `.zshrc` file เพื่อทำการ reload การตั้งค่า

```sh
source ~/.zshrc
```

ลง P10K เพิ่มเพื่อทำให้ terminal ดูสวยงามมากยิ่งขึ้น

```sh
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
```

จากนั้นแก้ไข `ZSH_THEME` ให้เป็น `powerlevel10k/powerlevel10k` เพื่อ load theme ดังกล่าวเข้าไป

```sh
# Update .zshrc file
nano ~/.zshrc

# Update Theme
ZSH_THEME="powerlevel10k/powerlevel10k"

# Reload
source ~/.zshrc
```

---

## ติดตั้ง NodeJS (v.22)

```sh
curl -sL https://deb.nodesource.com/setup_22.x -o /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
sudo apt install nodejs

# Verify
node -v
```

ติดตั้ง yarn เพิ่มเติม

```sh
# Install yarn
sudo npm install -g yarn

# Verify
yarn --version
```

## Sitemap

See the full [sitemap](https://iamthana.com/sitemap.md) for all pages.
