Skip to content

Instantly share code, notes, and snippets.

Last active October 13, 2019 17:06
What would you like to do?
[Linux only] Download and Install latest Android Studio anytime
# For most (if not all) Linux distros, there is no official repository package available to install Android Studio
# and still get regular updates. I made the below bash script that'll automatically scrape their download site for
# the download link of the latest version and can also optionally install it.
# As a forewarning, the method used to scrape the download link (sed and grep) may not always work, in which case,
# the script will notify it and exit without making any changes.
pageSource="/tmp/androidStudioHTML" && \
website="" && \
printf "\nGetting the download link for latest Android Studio (linux)..."
status=$(curl --head --location --connect-timeout 5 --write-out %{http_code} --silent --output /dev/null ${website})
if [ $status != 200 ]; then
printf "\nError: HTTP request failed to site. Skipping Android Studio installation!"
return 1
# save the page source into a temp file.
curl -s "$website" > "$pageSource" && \
# get all href links from the page source via sed, then grep out the filename linux.tar.gz, get first match only.
downloadURL="$(sed -n 's/.*href="\([^"]*\).*/\1/p' "$pageSource" | grep -i linux.tar.gz | head -1)" && \
# validate URL by checking filesize
filesize="$(wget "$downloadURL" --spider --server-response -O - 2>&1 | sed -ne '/Content-Length/{s/.*: //;p}')" && \
# If its atleast above 100megs, its safe to assume we got the right thing.
if (( $filesize > 100000000 )); then
printf "\n\nFound latest download link: $downloadURL"
printf "\n\nFailed to get the latest download link for Android Studio. Abort."
exit 1
read -p "Do you want to install Android Studio now? (y/N)" -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
printf "Finished\n\n"
exit 0
# ============================
# Downloading and Installing android studio
# ============================
printf "Downloading Android Studio..."
rm -f "$filename"
wget -O "$filename" "$downloadURL" -q --show-progress && \
installation_dir="$HOME/Programs/Android_Studio" && \
mkdir -p "$installation_dir"
printf "\n\nExtracting Android Studio archive..." && \
tar -xzf "$filename" -C "$installation_dir" --strip-components=1 && \
launcher="$installation_dir/bin/" && \
chmod +x "$launcher" && \
rm -f $filename && \
$launcher &
printf "\n\nAndroid Studio has been installed successfully.\n\nFinished\n\n"
Copy link

cyfrost commented Oct 13, 2019

Usage of this script:

bash <(curl -s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment