1

Instead of install both Android Studio and Android SDK at the user home directory (as suggested by the IDE), what would be the proper way of installing them for two or more users in the same machine?

The problem arose due system administrators necessity of:

  1. Installing the development tools for several users at a single computer.
  2. Installing the files at one machine an easily copy the same setup at several machines.
  3. Removing users without loosing development tools.
  4. Cleaner distro upgrades.
  5. Distro migrations (move from Ubuntu to Cento OS or Arch Linux for example).
JP Ventura
  • 5,564
  • 6
  • 52
  • 69

1 Answers1

1

TL; DR

Mac OS X already installs AS at /Applications folder by default.

Linux users should install the IDE at /opt/android-studio and create a symlink from bin/studio.sh to /usr/local/bin/studio (see the details section of how to create app launcher icon).

During the IDE install process, change the SDK location to /opt/google/android, allowing all users to have access to it. Don't forget to add write permissions to admin users, otherwise any AS and SDK updates will required sudo permission.

Once finished, the quick-dirty approach is adding this to /etc/profile:

#!/usr/bin/env bash

# WARNING
# Directly modify /etc/profile is not recommended.
# Please read the cleaner approach at the following details section.

export ANDROID_HOME=/opt/google/android
export ANDROID_NDK_HOME=${ANDROID_HOME}/ndk-bundle

# PATH exports were split ONLY due THIS post readability
export PATH=${ANDROID_HOME}/emulator:${PATH}
export PATH=${ANDROID_HOME}/tools:${PATH}
export PATH=${ANDROID_HOME}/platform-tools:${PATH}

then logout and login from OS in order to the modifications take effect.

Details

Even though is possible achieve the result using package managers (apt, brew, pacman, sdkmanager, yum,snap, etc), they rely on third-party package repositories that usually are not part of the official distro repositories.

Thus this solutions is more a matter of personal taste than an absolute truth.

One my read this post as an old-school way of configuring sysadmin tools, allowing you configure other stuff like Node.js, Google Cloud SDK, Heroku, etc.

That being said, suppose your username at Linux/OS X is stark and that there are more than one user registered at your workstation (potts and widow for example), but only you and widow are administrators.

1. Linux & Unix

We wish to create an SDK folder where multiple users may access both IDE and CLI tools without sharing the content of my personal folder (i.e. /home/stark or /Users/widow)

The solution is to install the SDK at /opt, since they are not part the distribution and the binaries downloaded from a third-party (i.e. not compiled by us through Makefile).

Since only root has permission to modify /opt, but it is not a good idea to use sudo every time you need to update the SDK, an old-school approach would be create a folder where only an specific group has write privileges:

sudo mkdir /opt/google/android
sudo chmod g+w /opt/google/android

# At Mac OS, use admin contrary to adm
usermod -a -G adm stark
usermod -a -G adm widow

I have used /opt/google/android because the same approach may be used for other Google SDK tools (Firebase or GCP for example), keeping all Google CLI tools at the same place.

/opt/
├── anaconda
├── gradle
├── jetbrains
│   ├── pycharm
│   ├── studio
│   └── webstorm
├── node
├── google
│   ├── android
│   ├── chrome
│   └── cloud
└── sonarqube

With the intention of exporting the CLI commands to all users, the best approach is configure the PATH variable at the highest profile level. For the purpose of the house clean and organized, instead of adding it directly to /etc/profile, let's create /etc/profile.d/android.sh as follows:

#!/usr/bin/env bash

export ANDROID_HOME=/opt/google/android
export ANDROID_NDK_HOME=${ANDROID_HOME}/ndk-bundle

# Emulator must come before tools directory
# See https://stackoverflow.com/questions/26483370
export PATH=${ANDROID_HOME}/emulator:${PATH}
export PATH=${ANDROID_HOME}/tools:${PATH}
export PATH=${ANDROID_HOME}/platform-tools:${PATH}

By default, Ubuntu already iterates over /etc/profile.d, exporting all shell defined at the *.sh files, consequently we may keep the configurations semantically organized:

/etc/profile.d/
├── anaconda.sh
├── android.sh
├── gcloud.sh
├── gradle.sh
├── node.sh
└── sonarqube.sh

Mac OS X does not export by default files at /etc/profile.d, requiring this code at /etc/profile:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

Unlike ~/.bash_profile and ~/.bashrc, that are loaded every time a new terminal is opened, /etc/profile and ~/.profile are loaded once you login into your system. Thus it is required re-login into your window manager (or OS X) before proceed to the IDE install process.

Keeping the SDK installed at /opt is useful because:

  • Allows you to remove your IDE without loosing the bunch of platform files already downloaded
  • If you keep separated partitions (like for /home), you may do the same for /opt and /usr/local.
  • System administrators can easily copy the development tools at several machines using rsync without have to worry with custom references at PATH for each /home user.

2. Install Android Studio

At some point during the IDE install process, it will be requested the location of (an existent) SDK. Change it to /opt/google/android rather than the default at your home directory.

Android Studio IDE

2.1. Linux

Following the same idea, download and install Android Studio at /opt:

mkdir /opt/jetbrains/

# At Mac OS, use admin contrary to adm
usermod -a -G adm stark
usermod -a -G adm widow

# Unpack and move
sudo tar -xvzf ~/Downloads/android-studio-ide-linux.tar.gz -C /opt/jetbrains/
sudo mv /opt/jetbrains/android-studio /opt/jetbrains/studio
sudo chgrp adm /opt/jetbrains/studio

# Allow calling Android Studio from command line
sudo ln -s /opt/jetbrains/studio/bin/studio.sh /usr/local/bin/studio

For invoking AS from launchers like Gnome Shell, Unity HUD, etc., create an app launcher at /usr/share/applications/jetbrains-studio.desktop as follows:

[Desktop Entry]
Version=1.0
Type=Application
Name=Android Studio
Icon=/opt/jetbrains/studio/bin/studio.png
Exec="/opt/jetbrains/studio/bin/studio.sh" %f
Comment=The Drive to Develop
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-studio

For users whom keep simultaneously several AS versions, you may keep separated folders such as:

# Stable release
/opt/jetbrains/studio/stable

# Unstable release
/opt/jetbrains/studio/canary

2.2 Mac OS X

Apple users will should install the IDE simply unpacking the *.dmg file at Applications folder.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
JP Ventura
  • 5,564
  • 6
  • 52
  • 69