# APT

The apt command is a powerful command-line tool, which works with Ubuntu's Advanced Packaging Tool (APT)

## 아카이브 변경 <a href="#undefined" id="undefined"></a>

`/etc/apt/sources.list` 파일과 `/etc/apt/sources.list.d` 디렉토리 안에 있는 파일에 아카이브 주소들을 통해 패키지 인덱스를 동기화하고 다운로드한다.

`/etc/apt/sources.list` 파일 내용을 출력하여 Source 리스트를 확인한다.

```
$ cat /etc/apt/sources.list
# 

# deb cdrom:[Ubuntu-Server 18.04.2 LTS _Bionic Beaver_ - Release amd64 (20190210)]/ bionic main restricted

#deb cdrom:[Ubuntu-Server 18.04.2 LTS _Bionic Beaver_ - Release amd64 (20190210)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted

...

```

우분투 서버 설치 과정 중 지역을 미국으로 선택했다면 아카이브 Source가 [`http://us.archive.ubuntu.com/ubuntu/`](http://us.archive.ubuntu.com/ubuntu/) 일 것이다. 미국에 있는 아카이브를 통해 소프트웨어를 다운받는 것보다 한국에 있는 아카이브를 통해 다운받으면 속도가 빠르기 때문에 카카오 에서 제공하는 우분투 미러 아카이브로 바꿔준다.

`/etc/apt/sources.list` 파일을 백업한다.

```
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.ori
```

`sed` 명령어를 통해 [`us.archive.ubuntu.com`](http://us.archive.ubuntu.com/) 를 [`mirror.kakao.com`](http://mirror.kakao.com/)로 치환한다.

```
$ sudo sed -i -e 's/us.archive.ubuntu.com/mirror.kakao.com/g' /etc/apt/sources.list
```

`/etc/apt/sources.list` 파일을 출력하면 아래와 같이 [`mirror.kakao.com`](http://mirror.kakao.com/) 로 바낀 것을 확인할 수 있다.

```
$ cat /etc/apt/sources.list
# 

# deb cdrom:[Ubuntu-Server 18.04.2 LTS _Bionic Beaver_ - Release amd64 (20190210)]/ bionic main restricted

#deb cdrom:[Ubuntu-Server 18.04.2 LTS _Bionic Beaver_ - Release amd64 (20190210)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirror.kakao.com/ubuntu/ bionic main restricted
# deb-src http://mirror.kakao.com/ubuntu/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirror.kakao.com/ubuntu/ bionic-updates main restricted
# deb-src http://mirror.kakao.com/ubuntu/ bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirror.kakao.com/ubuntu/ bionic universe
# deb-src http://mirror.kakao.com/ubuntu/ bionic universe
deb http://mirror.kakao.com/ubuntu/ bionic-updates universe
# deb-src http://mirror.kakao.com/ubuntu/ bionic-updates universe

...
```

`apt-get update` 시 <http://mirror.kakao.com/ubuntu> 을 통해 업데이트 되는 것을 볼 수 있다.

```
$ sudo apt-get update]($ sudo apt-get update
Get:1 http://mirror.kakao.com/ubuntu bionic InRelease [242 kB]
Get:2 http://mirror.kakao.com/ubuntu bionic-updates InRelease [88.7 kB] 
Get:3 http://mirror.kakao.com/ubuntu bionic-backports InRelease [74.6 kB])

...
```

## 패키지 업데이트 <a href="#undefined" id="undefined"></a>

우분투 서버에 설치되어 있는 패키지를 최신으로 업그레이드하기 위해 먼저 `apt-get update`로 최신 패키지정보를 받아온다.

```
$ sudo apt-get update
```

우분투 서버에 설치되어 있는 패키지들을 최신 버전으로 업그레이드를 한다.

```
$ sudo apt-get upgrade
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jkpark.gitbook.io/ubuntu/server/general-setting/apt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
