

# Install the CodeDeploy agent
<a name="codedeploy-agent-operations-install"></a>

To use CodeDeploy on EC2 instances or on-premises servers, the CodeDeploy agent must be installed first. We recommend installing and updating the CodeDeploy agent with AWS Systems Manager. For more information about Systems Manager, see [What is AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html). You can set up installation and scheduled updates of the CodeDeploy agent with Systems Manager in the console when you create your deployment groups.

You can also install the CodeDeploy agent directly from an S3 bucket with the command line.

For the recommended version to install, see [Version history of the CodeDeploy agent](codedeploy-agent.md#codedeploy-agent-version-history).

**Topics**
+ [Install the CodeDeploy agent using AWS Systems Manager](codedeploy-agent-operations-install-ssm.md)
+ [Install the CodeDeploy agent using the command line](codedeploy-agent-operations-install-cli.md)

# Install the CodeDeploy agent using AWS Systems Manager
<a name="codedeploy-agent-operations-install-ssm"></a>

You can use the AWS Management Console or the AWS CLI to install the CodeDeploy agent to your Amazon EC2 or on-premises instances by using AWS Systems Manager. You can choose to install a specific version or choose to always install the latest version of the agent. For more information about AWS Systems Manager, see [What is AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html). 

 Using AWS Systems Manager is the recommended method for installing and updating the CodeDeploy agent. You can also install the CodeDeploy agent from an Amazon S3 bucket. For information about using an Amazon S3 download link, see [Install the CodeDeploy agent using the command line](codedeploy-agent-operations-install-cli.md). 

**Topics**
+ [Prerequisites](#install-codedeploy-agent-prereqs)
+ [Install the CodeDeploy agent](#download-codedeploy-agent-on-EC2-Instance)

## Prerequisites
<a name="install-codedeploy-agent-prereqs"></a>

Follow the steps in [Getting started with CodeDeploy](getting-started-codedeploy.md) to set up IAM permissions and the AWS CLI.

If installing the CodeDeploy agent on an on-premises server with Systems Manager, you must register your on-premises server with Amazon EC2 Systems Manager. For more information, see [ Setting up Systems Manager in hybrid environments](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-managedinstances.html) in the *AWS Systems Manager User Guide*.

## Install the CodeDeploy agent
<a name="download-codedeploy-agent-on-EC2-Instance"></a>

Before you can use Systems Manager to install the CodeDeploy agent, you must make sure that the instance is configured correctly for Systems Manager.

### Installing or updating the SSM agent
<a name="update-SSM-Agent-EC2instance"></a>

On an Amazon EC2 instance, the CodeDeploy agent requires that the instance is running version 2.3.274.0 or later. Before you install the CodeDeploy agent, update or install SSM agent on the instance if you haven't already done so. 

The SSM agent comes preinstalled on some Amazon EC2 AMIs provided by AWS. For more information, see [Amazon Machine Images (AMIs) with SSM agent preinstalled](https://docs.aws.amazon.com/systems-manager/latest/userguide/ami-preinstalled-agent.html).

**Note**  
Make sure that the instance's operating system is also supported by the CodeDeploy agent. For more information, see [Operating systems supported by the CodeDeploy agent](codedeploy-agent.md#codedeploy-agent-supported-operating-systems).

For information about installing or updating SSM agent on an instance running Linux, see [Installing and configuring the SSM agent on Linux instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-ssm-agent.html) in the *AWS Systems Manager User Guide*.

For information about installing or updating SSM agent on an instance running Windows Server, see [ Installing and configuring SSM agent on Windows instances](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-ssm-win.html) in the *AWS Systems Manager User Guide*.

### (Optional) Verify Systems Manager prerequisites
<a name="install-codedeploy-agent-minimum-requirements"></a>

Before you use Systems Manager Run Command to install the CodeDeploy agent, verify that your instances meet the minimum Systems Manager requirements. For more information, see [Setting up AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-setting-up.html) in the *AWS Systems Manager User Guide*.

### Install the CodeDeploy agent
<a name="install-codedeploy-agent-EC2"></a>

With SSM, you can install the CodeDeploy once or set up a schedule to install new versions.

 To install the CodeDeploy agent, choose the `AWSCodeDeployAgent` package while you follow the steps in [Install or update packages with AWS Systems Manager distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor-working-with-packages-deploy.html). 

# Install the CodeDeploy agent using the command line
<a name="codedeploy-agent-operations-install-cli"></a>

**Note**  
We recommend installing the CodeDeploy agent with AWS Systems Manager to be able to configure scheduled updates of the agent. For more information, see [Install the CodeDeploy agent using AWS Systems Manager](codedeploy-agent-operations-install-ssm.md).

Use the following topics to install and run the CodeDeploy agent using the command line.

**Topics**
+ [Install the CodeDeploy agent for Amazon Linux or RHEL](codedeploy-agent-operations-install-linux.md)
+ [Install the CodeDeploy agent for Ubuntu Server](codedeploy-agent-operations-install-ubuntu.md)
+ [Install the CodeDeploy agent for Windows Server](codedeploy-agent-operations-install-windows.md)

# Install the CodeDeploy agent for Amazon Linux or RHEL
<a name="codedeploy-agent-operations-install-linux"></a>

Sign in to the instance, and run the following commands, one at a time. Running the command `sudo yum update` first is considered best practice when using `yum` to install packages, but you can skip it if you do not wish to update all of your packages.

```
sudo yum update
```

```
sudo yum install ruby
```

```
sudo yum install wget
```

(Optional) To clean the AMI of any previous agent caching information, run the following script:

```
#!/bin/bash
CODEDEPLOY_BIN="/opt/codedeploy-agent/bin/codedeploy-agent"
$CODEDEPLOY_BIN stop
yum erase codedeploy-agent -y
```

Change to your home directory:

```
cd /home/ec2-user
```

**Note**  
In the previous command, `/home/ec2-user` represents the default user name for an Amazon Linux or RHEL Amazon EC2 instance. If your instance was created using a custom AMI, the AMI owner might have specified a different default user name. 

Download the CodeDeploy agent installer:

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

*bucket-name* is the name of the Amazon S3 bucket that contains the CodeDeploy Resource Kit files for your region, and *region-identifier* is the identifier for your region.

For example:

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

For a list of bucket names and region identifiers, see [Resource kit bucket names by Region](resource-kit.md#resource-kit-bucket-names).

Set execute permissions on the `install` file:

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

To install the latest version of the CodeDeploy agent:
+ 

  ```
  sudo ./install auto
  ```

To install a specific version of the CodeDeploy agent:
+ List the available versions in your region:

  ```
  aws s3 ls s3://aws-codedeploy-region-identifier/releases/ --region region-identifier | grep '\.rpm$'
  ```
+ Install one of the versions:

  ```
  sudo ./install auto -v releases/codedeploy-agent-version.noarch.rpm
  ```
**Note**  
AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.7.x.

To check that the service is running, run the following command:

```
systemctl status codedeploy-agent
```

If the CodeDeploy agent is installed and running, you should see a message like `The AWS CodeDeploy agent is running`.

If you see a message like `error: No AWS CodeDeploy agent running`, start the service and run the following two commands, one at a time:

```
systemctl start codedeploy-agent
```

```
systemctl status codedeploy-agent
```

# Install the CodeDeploy agent for Ubuntu Server
<a name="codedeploy-agent-operations-install-ubuntu"></a>

**Note**  
We recommend installing the CodeDeploy agent with AWS Systems Manager to be able to configure scheduled updates of the agent. For more information, see [Install the CodeDeploy agent using AWS Systems Manager](codedeploy-agent-operations-install-ssm.md).

**To install the CodeDeploy agent on Ubuntu Server**

1. Sign in to the instance.

1. Enter the following commands, one after the other:

   ```
   sudo apt update
   ```

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

   ```
   sudo apt install wget
   ```

1. Enter the following command:

   ```
   cd /home/ubuntu
   ```

   */home/ubuntu* represents the default user name for an Ubuntu Server instance. If your instance was created using a custom AMI, the AMI owner might have specified a different default user name. 

1. Enter the following command:

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

   *bucket-name* is the name of the Amazon S3 bucket that contains the CodeDeploy Resource Kit files for your region, and *region-identifier* is the identifier for your region.

   For example:

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

   For a list of bucket names and region identifiers, see [Resource kit bucket names by Region](resource-kit.md#resource-kit-bucket-names).

1. Enter the following command:

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

1. Do one of the following:
   + To install the latest version of the CodeDeploy agent on any supported version of Ubuntu Server *except* 20.04:

     ```
     sudo ./install auto
     ```
   + To install the latest version of the CodeDeploy agent on Ubuntu Server 20.04:
**Note**  
Writing the output to a temporary log file is a workaround that should be used while we address a known bug with the `install` script on Ubuntu Server 20.04.

     ```
     sudo ./install auto > /tmp/logfile
     ```
   + To install a specific version of the CodeDeploy agent on any supported version of Ubuntu Server *except* 20.04:
     + List the available versions in your region:

       ```
       aws s3 ls s3://aws-codedeploy-region-identifier/releases/ --region region-identifier | grep '\.deb$'
       ```
     + Install one of the versions:

       ```
       sudo ./install auto -v releases/codedeploy-agent-###.deb
       ```
**Note**  
AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.7.x.
   + To install a specific version of the CodeDeploy agent on Ubuntu Server 20.04:
     + List the available versions in your region:

       ```
       aws s3 ls s3://aws-codedeploy-region-identifier/releases/ --region region-identifier | grep '\.deb$'
       ```
     + Install one of the versions:

       ```
       sudo ./install auto -v releases/codedeploy-agent-###.deb > /tmp/logfile
       ```
**Note**  
Writing the output to a temporary log file is a workaround that should be used while we address a known bug with the `install` script on Ubuntu Server 20.04.
**Note**  
AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.7.x.

**To check that the service is running**

1. Enter the following command:

   ```
   systemctl status codedeploy-agent
   ```

   If the CodeDeploy agent is installed and running, you should see a message like `The AWS CodeDeploy agent is running`.

1. If you see a message like `error: No AWS CodeDeploy agent running`, start the service and run the following two commands, one at a time:

   ```
   systemctl start codedeploy-agent
   ```

   ```
   systemctl status codedeploy-agent
   ```

# Install the CodeDeploy agent for Windows Server
<a name="codedeploy-agent-operations-install-windows"></a>

On Windows Server instances, you can use one of these methods to download and install the CodeDeploy agent:
+ Use AWS Systems Manager (recommended)
+ Run a series of Windows PowerShell commands.
+ Choose a direct download link.
+ Run an Amazon S3 copy command.

**Note**  
The folder that the CodeDeploy agent is installed to is `C:\Program Data\Amazon\CodeDeploy`. Make sure there are no directory junctions or symlinks on this path.

**Topics**
+ [Use Systems Manager](#codedeploy-agent-operations-install-system-manager)
+ [Use Windows PowerShell](#codedeploy-agent-operations-install-windows-powershell)
+ [Use a direct link](#codedeploy-agent-operations-install-windows-direct-link)
+ [Use an Amazon S3 copy command](#codedeploy-agent-operations-install-windows-s3-copy)

## Use Systems Manager
<a name="codedeploy-agent-operations-install-system-manager"></a>

Follow the instructions in [Install the CodeDeploy agent using AWS Systems Manager](codedeploy-agent-operations-install-ssm.md) to install the CodeDeploy agent.

## Use Windows PowerShell
<a name="codedeploy-agent-operations-install-windows-powershell"></a>

Sign in to the instance, and run the following commands in Windows PowerShell:

1.  Require that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher. If you are prompted to change the execution policy, type "**Y**." 

   ```
    Set-ExecutionPolicy RemoteSigned
   ```

1.  Load the AWS Tools for Windows PowerShell. 

   ```
   Import-Module AWSPowerShell
   ```

1.  Create a directory into where the CodeDeploy agent installation file is downloaded. 

   ```
   New-Item -Path "c:\temp" -ItemType "directory" -Force
   ```

1. Configure AWS credentials using the `Set-AWSCredential` and `Initialize-AWSDefaultConfiguration` commands. For more information, see [Using AWS credentials](https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html) in the *AWS tools for PowerShell User Guide*.

1.  Download the CodeDeploy agent installation file. 
**Note**  
AWS supports the latest minor version of the CodeDeploy agent. Currently the latest minor version is 1.7.x.

   To install the latest version of the CodeDeploy agent:
   + 

     ```
     powershell.exe -Command Read-S3Object -BucketName bucket-name -Key latest/codedeploy-agent.msi -File c:\temp\codedeploy-agent.msi
     ```

   To install a specific version of the CodeDeploy agent:
   + 

     ```
     powershell.exe -Command Read-S3Object -BucketName bucket-name -Key releases/codedeploy-agent-###.msi -File c:\temp\codedeploy-agent.msi
     ```

   *bucket-name* is the name of the Amazon S3 bucket that contains the CodeDeploy Resource Kit files for your region. For example, for the US East (Ohio) Region, replace *bucket-name* with `aws-codedeploy-us-east-2`. For a list of bucket names, see [Resource kit bucket names by Region](resource-kit.md#resource-kit-bucket-names).

1.  Run the CodeDeploy agent installation file. 

   ```
   c:\temp\codedeploy-agent.msi /quiet /l c:\temp\host-agent-install-log.txt
   ```

To check that the service is running, run the following command:

```
powershell.exe -Command Get-Service -Name codedeployagent
```

 If the CodeDeploy agent was just installed and has not been started, then after running the **Get-Service** command, under **Status**, you should see **Start...**:

```
Status     Name                DisplayName
------     ----                -----------
Start...   codedeployagent    CodeDeploy Host Agent Service
```

If the CodeDeploy agent is already running, after running the **Get-Service** command, under **Status**, you should see **Running**:

```
Status     Name                DisplayName
------     ----                -----------
Running    codedeployagent    CodeDeploy Host Agent Service
```

## Use a direct link
<a name="codedeploy-agent-operations-install-windows-direct-link"></a>

If the browser security settings on the Windows Server instance provide the permissions (for example, to `https://s3.*.amazonaws.com`), you can use a direct link for your Region to download the CodeDeploy agent and then run the installer manually.

The link is:

```
https://s3.region.amazonaws.com/aws-codedeploy-region/latest/codedeploy-agent.msi
```

...where *region* is the AWS Region where you're deploying your application.

For example:

```
https://s3.af-south-1.amazonaws.com/aws-codedeploy-af-south-1/latest/codedeploy-agent.msi
```

**Important**  
Obtain the `.msi` file from the same Region as your CodeDeploy application. Choosing a different Region may cause `inconsistent region` failures in the `codedeploy-agent-log` file when you run the `.msi` file.

## Use an Amazon S3 copy command
<a name="codedeploy-agent-operations-install-windows-s3-copy"></a>

If the AWS CLI is installed on the instance, you can use the Amazon S3 [cp](https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html) command to download the CodeDeploy agent and then run the installer manually. For information, see [Install the AWS Command Line Interface on Microsoft Windows](https://docs.aws.amazon.com/cli/latest/userguide/awscli-install-windows.html). 

The Amazon S3 command is:

```
aws s3 cp s3://aws-codedeploy-region/latest/codedeploy-agent.msi codedeploy-agent.msi --region region
```

...where *region* is the AWS Region where you're deploying your application.

For example:

```
aws s3 cp s3://aws-codedeploy-af-south-1/latest/codedeploy-agent.msi codedeploy-agent.msi --region af-south-1
```