Trouble installing AWS CLI version 2

Contributor II

Ok, Let me preface this by first stating that scripting is NOT my strong point.
I'm attempting to install AWS CLI version 2 for all users per the instructions on:

Attempting to run the commands via policy result in an exit code 127. I've found a few posts about AWSCLI version 1, but none of the solutions seem to work. Any suggestions?


Contributor III

@rpayne Could you post your script, please?

Contributor III

@rpayne Just put a rough script based on the AWS info.


#  download the AWSCLIV2.pkg to tmp folder and return the http_code
response=$(/usr/bin/curl --silent --write-out "%{http_code}" "" --output /tmp/AWSCLIV2.pkg)

checkForV1() {
  # Uninstall the AWS CLI version 1 bundled installer
  # The bundled installer puts everything inside of the installation directory except the optional symlink, so to uninstall, you just need to delete those two items.

  if [[ -d  /usr/local/aws  ]]; then
    echo  "AWD CLI version 1 found"
    /bin/rm -rf /usr/local/aws
    /bin/rm /usr/local/bin/aws
    echo  "AWD CLI version 1 not found"


# check if the download was successful
if [[ $response -eq 200  ]]; then
  echo "package downloaded"

  # Important
  # AWS CLI versions 1 and 2 use the same aws command name. If you have both versions installed, your computer uses the first one found in your search path. If you previously installed AWS CLI version 1, we recommend that you do one of the following to use AWS CLI version 2:
  # Recommended – Uninstall AWS CLI version 1 and use only AWS CLI version 2.

  # install the package
  /usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target / || echo "Ops! Problem with the installer" ; exit 1

  # clean up
  /bin/rm /tmp/AWSCLIV2.pkg

  echo "download error: $response"
  # exit the curl download code so we can see in the Jamf reports where it is failing.
  exit $response

exit 0

Tested on 10.15.6 VM and looks OK

New Contributor III

@Mauricio Hey, thanks for the script.

I seem to be getting the following after it installs successfully.

Running script Install AWS CLI 2...
Script exit code: 1
Script result: package downloaded
AWD CLI version 1 not found
installer: Package name is AWS Command Line Interface
installer: Upgrading at base path /
installer: The upgrade was successful.
Error running script: return code was 1.

Contributor III

@kissland Try to change the line of the installer.


/usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target / || echo "Ops! Problem with the installer" ; exit 1


/usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target /

You will be able to get the installer output in the log.
Hope that helps.

New Contributor III

@Mauricio Seems to work now, how can I check whether the $response returns anything? After running the script in terminal, when I run $response its just blank

Contributor III

@kissland Not sure if I understand the question.

If you run the curl command in Terminal that variable will be available


If you run the script in the Terminal then the "package downloaded" is the clue that $response was 200, that variable is only available to the script.


Does it make sense?