Posted: November 08, 2022

@SecFails

Photo Credit: @SecFails

Rootless awscli: Install awscli2 the safe way

.

The infamous /opt folder

Imagine it's Monday, and you're excited to start working on your new project. The first step is to set up your environment, so you turn to Google for guidance on how to install your favorite software. However, what you find is a flood of tutorials suggesting that you install it in the infamous /opt folder.
After you finally manage to install it, you realize that you can't use it without adding our possessive friend sudo on every call.
It's frustrating, isn't it?

The reason behind this predicament lies in the fact that the /opt folder is system-owned. This convention of installing third-party software in the /opt folder comes from the FHS convention from 1994 and it's outdated. Softwares like IntelliJ and PyCharm, which are installed in the /opt folder by default, have root access to your files.

However, there is a newer and better alternative!

The .local folder

This convention was introduced in 2007 as part of the XDG Base Directory Specification. The .local folder is user-owned and specifically designed for user-specific files and applications. It even mirrors the root folder / structure, making it intuitive to navigate.

In case of awscli, the official guide relies on installing at /usr/local which is also system-owned, but since we have the XDG convention, why not follow it and install on the .local folder along with other softwares, making it easier to backup your stuff?

Installation

  1. First download the zip file from https://awscli.amazonaws.com/
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
  1. Install at .local
./aws/install --bin-dir ~/.local/bin --install-dir ~/.local/aws-cli --update
  1. Make awscli binary discoverable by adding the binaries location into PATH at .bashrc
# if you haven't previously done yet
echo PATH=\"\$HOME/.local/bin:\$PATH\" >> ${HOME}/.bashrc

# to reload .bashrc env into this terminal
source ~/.bashrc 

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

© 2022 — Matheus Toazza TuraLegal Information