

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 安裝適用於 Ubuntu Server 的 CodeDeploy 代理程式
<a name="codedeploy-agent-operations-install-ubuntu"></a>

**注意**  
建議您使用 安裝 CodeDeploy 代理程式，以便 AWS Systems Manager 能夠設定代理程式的排程更新。如需詳細資訊，請參閱[使用 安裝 CodeDeploy 代理程式 AWS Systems Manager](codedeploy-agent-operations-install-ssm.md)。

**在 Ubuntu Server 上安裝 CodeDeploy 代理程式**

1. 登入執行個體。

1. 依序輸入下列命令：

   ```
   sudo apt update
   ```

   ```
   sudo apt install ruby-full
   ```

   ```
   sudo apt install wget
   ```

1. 輸入以下命令：

   ```
   cd /home/ubuntu
   ```

   */home/ubuntu* 代表 Ubuntu Server 執行個體的預設使用者名稱。如果您的執行個體是使用自訂的 AMI 建立的，AMI 擁有者可能已指定不同的預設使用者名稱。

1. 輸入以下命令：

   ```
   wget https://bucket-name.s3.region-identifier.amazonaws.com/latest/install
   ```

   *bucket-name* 是 Amazon S3 儲存貯體的名稱，其中包含您區域的 CodeDeploy 資源套件檔案，而 *region-identifier* 是您區域的識別符。

   例如：

   `https://aws-codedeploy-us-east-2.s3.us-east-2.amazonaws.com/latest/install`

   如需儲存貯體名稱和區域識別符的清單，請參閱 [依區域顯示的資源套件儲存貯體名稱](resource-kit.md#resource-kit-bucket-names)。

1. 輸入以下命令：

   ```
   chmod +x ./install
   ```

1. 執行以下任意一項：
   + 若要在任何支援的 Ubuntu Server 版本上安裝最新版本的 CodeDeploy 代理程式，*但* 20.04 除外：

     ```
     sudo ./install auto
     ```
   + 若要在 Ubuntu Server 20.04 上安裝最新版本的 CodeDeploy 代理程式：
**注意**  
將輸出寫入臨時日誌檔案是解決 Ubuntu Server 20.04 上`install`指令碼的已知錯誤時應該使用的解決方法。

     ```
     sudo ./install auto > /tmp/logfile
     ```
   + 若要在任何支援的 Ubuntu Server 版本上安裝 CodeDeploy 代理程式的特定版本，*但* 20.04 除外：
     + 列出您區域中可用的版本：

       ```
       aws s3 ls s3://aws-codedeploy-region-identifier/releases/ --region region-identifier | grep '\.deb$'
       ```
     + 安裝其中一個版本：

       ```
       sudo ./install auto -v releases/codedeploy-agent-###.deb
       ```
**注意**  
AWS 支援 CodeDeploy 代理程式的最新次要版本。目前最新的次要版本為 1.7.x。
   + 若要在 Ubuntu Server 20.04 上安裝特定版本的 CodeDeploy 代理程式：
     + 列出您區域中可用的版本：

       ```
       aws s3 ls s3://aws-codedeploy-region-identifier/releases/ --region region-identifier | grep '\.deb$'
       ```
     + 安裝其中一個版本：

       ```
       sudo ./install auto -v releases/codedeploy-agent-###.deb > /tmp/logfile
       ```
**注意**  
將輸出寫入臨時日誌檔案是解決 Ubuntu Server 20.04 上`install`指令碼的已知錯誤時應該使用的解決方法。
**注意**  
AWS 支援 CodeDeploy 代理程式的最新次要版本。目前最新的次要版本為 1.7.x。

**檢查服務是否正在執行**

1. 輸入以下命令：

   ```
   systemctl status codedeploy-agent
   ```

   如果已安裝並執行 CodeDeploy 代理程式，您應該會看到類似 的訊息`The AWS CodeDeploy agent is running`。

1. 如果您看到類似 `error: No AWS CodeDeploy agent running` 的訊息，請啟動服務並執行以下兩個命令，一次一個：

   ```
   systemctl start codedeploy-agent
   ```

   ```
   systemctl status codedeploy-agent
   ```