ตั้งค่า Ubuntu Server

ubuntu

January 14, 2024

Introduction

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

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

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

sudo apt update && sudo apt upgrade -y

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

sudo timedatectl set-timezone Asia/Bangkok

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

sudo apt install build-essential

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

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

sudo apt update
sudo apt install curl -y

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

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

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

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

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

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

docker --version

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

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

# 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 เข้าไป

nano ~/.zshrc

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

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

source ~/.zshrc

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

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 ดังกล่าวเข้าไป

# Update .zshrc file
nano ~/.zshrc

# Update Theme
ZSH_THEME="powerlevel10k/powerlevel10k"

# Reload
source ~/.zshrc

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

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 เพิ่มเติม

# Install yarn
sudo npm install -g yarn

# Verify
yarn --version