Moving Android Studio from home to system folders

Android Studio takes up a lot of space with its SDKs and virtual devices. The home folder gets full quickly. One option would be to move the entire Android Studio suite to its own folder in one of the system folders. We will use /opt folder but /usr/local can also be used.  First, we create the directory structure at /opt/

$ su
$ cd /opt
$ mkdir Android

The /opt/Android folder will hold the Android Studio, the SDKs, and the AVDs.

$ mv /home/me/android-studio /opt/Android
$ mv /home/me/Sdk /opt/Android

The AVD folders are trickier as they are in the hidden folders in the users’ home directory.

$ cd /home/me/.android
$ mv avd /opt/Android

Now we need to link the moved folders so that Android Studio can access them.

1. Link the AVD folder as normal user

Open another terminal as the regular user

$ cd ~/.android
$ ln -s /opt/Android/avd avd

We then verify that the link points to the right directory

$ ls -l
lrwxrwxrwx 1 me mygroup 16 Oct 13 09:46 avd -> /opt/Android/avd/

2. Create a desktop file for Android Studio

This will allow the user to start Android Studio from the Ubuntu dash. Open terminal as a regular user and create a new file called android-studio.desktop

$ cd ~/.local/share/applications
$ gedit android-studio.desktop

We add these values to the file and save it.

[Desktop Entry]
Name=Android Studio
Exec=/opt/Android/android-studio/bin/studio.sh
Icon=/opt/Android/android-studio/bin/studio.png
Terminal=false
Type=Application
Categories=Utility;Application;

3. Link the SDK location from inside Android Studio

Open the Android Studio from dash (start typing android and it should pop up along with the Android Studio icon)

File -> Settings -> System Settings -> Android SDK

Set the path to the Android SDK location

If we have moved the Project directory then we will need to open one project manually and Android Studio will automatically detect the new location of the projects.

Notice that Android Studio with all its packages takes upwards of 9 GB

$ cd /opt/Android/
$ du -sh
8.8G .

 

Leave a comment