# Cài đặt ứng dụng trên Ubuntu Server

Đây là các phương pháp phổ biến nhất:

### 1. Sử dụng APT (Package Manager mặc định)

bash Copy

```bash
# Cập nhật danh sách gói
sudo apt update

# Cài đặt ứng dụng (ví dụ: nginx)
sudo apt install nginx

# Cài đặt nhiều gói cùng lúc
sudo apt install package1 package2 package3

# Cài đặt phiên bản cụ thể
sudo apt install nginx=1.18.0-0ubuntu1
```

### 2. Sử dụng Snap

bash Copy

```bash
# Tìm kiếm ứng dụng
snap find firefox

# Cài đặt
sudo snap install firefox

# Cài đặt với channel cụ thể (stable/candidate/beta/edge)
sudo snap install node --channel=18/stable

# Cài đặt classic confinement
sudo snap install code --classic
```

### 3. Sử dụng Docker

bash Copy

```bash
# Cài đặt Docker trước
sudo apt install docker.io

# Chạy container
sudo docker run -d -p 80:80 nginx

# Hoặc sử dụng Docker Compose
# Tạo file docker-compose.yml rồi chạy:
sudo docker-compose up -d
```

### 4. Cài đặt từ Source Code

bash Copy

```bash
# Ví dụ: Cài đặt từ GitHub
git clone https://github.com/user/repo.git
cd repo

# Build từ source (tùy thuộc vào ngôn ngữ)
# Node.js:
npm install && npm run build

# Python:
pip install -r requirements.txt

# Go:
go build

# C/C++:
./configure && make && sudo make install
```

### 5. Cài đặt file .deb

bash Copy

```bash
# Tải file .deb về
wget https://example.com/app.deb

# Cài đặt bằng dpkg
sudo dpkg -i app.deb

# Fix dependencies nếu có lỗi
sudo apt --fix-broken install
```

### 6. Cài đặt từ PPA (Personal Package Archive)

bash Copy

```bash
# Thêm PPA repository
sudo add-apt-repository ppa:nginx/stable

# Cập nhật và cài đặt
sudo apt update
sudo apt install nginx
```

### Các lệnh quản lý hữu ích

Table

| Lệnh                      | Mô tả                   |
| ------------------------- | ----------------------- |
| `sudo apt remove package` | Gỡ cài đặt              |
| `sudo apt purge package`  | Gỡ cài đặt + xóa config |
| `sudo apt autoremove`     | Xóa dependencies thừa   |
| `apt search keyword`      | Tìm kiếm gói            |
| `apt show package`        | Xem thông tin gói       |
| `dpkg -l \| grep package` | Kiểm tra đã cài chưa    |

### Ví dụ thực tế: Cài đặt LAMP Stack

bash Copy

```bash
# Update hệ thống
sudo apt update && sudo apt upgrade -y

# Cài Apache
sudo apt install apache2 -y

# Cài MySQL
sudo apt install mysql-server -y
sudo mysql_secure_installation

# Cài PHP
sudo apt install php libapache2-mod-php php-mysql -y

# Restart Apache
sudo systemctl restart apache2
```

### Lưu ý quan trọng

1. **Luôn update trước khi cài**: `sudo apt update`
2. **Kiểm tra port**: Đảm bảo port cần thiết đã mở (`sudo ufw allow 80/tcp`)
3. **Service auto-start**: `sudo systemctl enable servicename`
4. **Log files**: Kiểm tra `/var/log/` nếu có lỗi

Bạn muốn cài đặt ứng dụng cụ thể nào? Tôi có thể hướng dẫn chi tiết hơn.
