Installing EC2 CLI tools

Setting Up the Amazon EC2 CLI Tools on RHEL, Ubuntu, or Mac OS X

You must complete the following setup tasks before you can use the Amazon EC2 CLI tools on your own computer.

Download and Install the CLI Tools

To download and install the CLI tools

  1. Download the tools. The CLI tools are available as a .zip file on this site: Amazon EC2 CLI Tools. You can also download them with the wget utility.
  2. (Optional) Verify that the CLI tools package has not been altered or corrupted after publication. For more information about authenticating the download before unzipping the file, see (Optional) Verify the Signature of the CLI Tools Download.
  3. Unzip the files into a suitable installation directory, such as /usr/local/ec2.
    sudo mkdir /usr/local/ec2
    sudo unzip -d /usr/local/ec2
  1. Notice that the .zip file contains a folder ec2-api-tools-x.x.x.x, where x.x.x.x is the version number of the tools (for example, ec2-api-tools-

Tell the Tools Where Java Lives

The Amazon EC2 CLI tools require Java. If you don’t have Java 1.7 or later installed, download and install Java. Either a JRE or JDK installation is acceptable. To view and download JREs for a range of platforms, see Java Downloads.


Instances that you launch using the Amazon Linux AMI already include Java.

The Amazon EC2 CLI read the JAVA_HOME environment variable to locate the Java runtime. This environment variable should specify the full path of the directory that contains a subdirectory named bin that contains the Java executable you installed (java.exe).

To set the JAVA_HOME environment variable on Linux/Unix and Mac OS X

  1. You can verify whether you have Java installed and where it is located using the following command:
    $ which java

    The following is example output.


    If the previous command does not return a location for the Java binary, you need to install Java. For help installing Java on your platform, see Java Downloads.

    To install Java on Ubuntu systems, execute the following command:

    ubuntu:~$ sudo apt-get install -y openjdk-7-jre
  2. Find the Java home directory on your system. The which java command executed earlier returns Java’s location in the $PATH environment variable, but in most cases this is a symbolic link to the actual program; symbolic links do not work for the JAVA_HOME environment variable, so you need to locate the actual binary.
    1. (Linux only) For Linux systems, you can recursively run the file command on the which java output until you find the binary.
      $ file $(which java)
      /usr/bin/java: symbolic link to `/etc/alternatives/java'

      The /usr/bin/java location is actually a link to /etc/alternatives/java, so you need to run the file command on that location to see whether that is the real binary.

      $ file /etc/alternatives/java
      /etc/alternatives/java: symbolic link to `/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'

      This returns a new location, which is the actual binary. Verify this by running the file command on this location.

      $ file /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
      /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java: ELF 64-bit LSB executable...

      This location is the actual binary (notice that it is listed as an executable). The Java home directory is where bin/java lives; in this example, the Java home directory is/usr/lib/jvm/java-7-openjdk-amd64/jre.

    2. (Mac OS X only) For Mac OS X systems, the /usr/libexec/java_home command returns a path suitable for setting the JAVA_HOME variable.
      $ /usr/libexec/java_home
  3. Set JAVA_HOME to the full path of the Java home directory.
    1. (Linux only) For the Linux example above, set the JAVA_HOME variable to the directory where bin/java was located in Step 2.a.
      $ export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64/jre"


      If you are using Cygwin, JAVA_HOME should contain a Windows path.

    2. (Mac OS X only) For the Mac OS X example above, set the JAVA_HOME variable to $(/usr/libexec/java_home). The following command sets this variable to the output of thejava_home command; the benefit of setting the variable this way is that it updates to the correct value if you change the location of your Java installation later.
      $ export JAVA_HOME=$(/usr/libexec/java_home)
  4. You can verify your JAVA_HOME setting using this command.
    $ $JAVA_HOME/bin/java -version

    If you’ve set the environment variable correctly, the output looks something like this.

    java version "1.7.0_55"
    OpenJDK Runtime Environment (IcedTea6 2.4.7) (7u55-2.4.7-1ubuntu0.12.04.2)
    OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
  5. Add this environment variable definition to your shell start up scripts so that it is set every time you log in or spawn a new shell. The name of this startup file differs across platforms (in Mac OS X, this file is commonly called ~/.bash_profile and in Linux, it is commonly called ~/.profile), but you can find it with the following command:
    $ ls -al ~ | grep profile

    If the file does not exist, you can create it. Use your favorite text editor to open the file that is listed by the previous command, or to create a new file with that name. Then edit it to add the variable definition you set in Step 3.

  6. Verify that the variable is set properly for new shells by opening a new terminal window and testing that the variable is set with the following command.


    If the following command does not correctly display the Java version, try logging out, logging back in again, and then retrying the command.

    $ $JAVA_HOME/bin/java -version



About sangroyaamit

I am a PhD student in computer science at INRIA Grenoble.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s