82

I installed Android Studio in my /opt directory without a hitch and have been using it. Recently, though, Android Studio informed me of an update. It won't perform the update, however, because it says it doesn't have Read / Write permissions in the opt directory where it's installed.

Can anyone recommend the best remedy for this situation? I would prefer not to move my installation to another directory. I also don't know that I want to change permissions on the directory, though I might be tempted to do so for the update, then revert it back.

Error message:

Studio does not have write access to /opt/android-studio. Please run it by a privileged user to update
Yushin
  • 109
wayneeusa
  • 959
  • 1
  • 8
  • 15
  • How are you trying to update ? How did you install ? PPA ? Can you run android studio as root ? ie sudo /opt/android-studio and then update ? – Mark Kirby Jun 30 '15 at 14:00
  • 1
    I guess you copied it to the /opt/ directory. I won't recommend keeping it there, so you don't have to bother with the permission issues. It is best to use umake to set up your Android development environment. – Gayan Weerakutti Jun 30 '15 at 14:39
  • @markkirby I copied it there and used the installation script studio.sh I would run by sudo, but studio.sh starts the installation again. Surprised that I don't see a file to run to just start the program. Maybe I should gedit the installation script to see where the executable is .. – wayneeusa Jul 03 '15 at 17:38
  • i recommend awarding one of the answers the status of correct answer. otherwise, it may be misleading for users who come by this post in the future - if a correct answer has not been awarded 1 year after, it means that neither answer is correct. When, in fact, both efficiently address the problem at hand. i UPVOTED your question, BTW : ) – tony gil Aug 21 '16 at 09:51
  • 1
    I ran into permission trouble routinely by leaving /opt at default root permissions, and I will not leave everything in my home directory; That has its own pitfalls. There just isn't enough double checking done by install scripts to guide you through potential pitfalls, and sudo just will not save the day. For the love of Mike, this is still happening in 2020. I gave up opened up permissions on /opt and called it a day. Does it worry me? You bet. But for a non-server system; notsomuch.... – tgm1024--Monica was mistreated Oct 11 '20 at 01:28

6 Answers6

138

I changed the owner of the android studio directory from root to my user account and it worked. Here is the command, where $USER will change by itself to your current active user:

sudo chown -R $USER:$USER /opt/android-studio
Rinzwind
  • 299,756
Latif
  • 1,396
8

You can move the directory from /opt to your home using comand:

sudo cp -r /opt/android-studio ~/

Or to give permissions you have to use chmod:

sudo chmod +w /opt/android-studio/some-file

to add permissions to all dir recursive:

sudo chmod +w -R /opt/android-studio/some-file

Take a look on my answer https://askubuntu.com/a/638799/150504 that explain a little about chmod and how to use

Maythux
  • 84,289
  • Do I need to specify the specific executable file that will have this permission for the folder? I tried it with the studio.sh, but I don't think that's the actual file that's running when I click the icon to run android studio. – wayneeusa Jul 03 '15 at 17:52
  • didnt work for me. When creating directory. tried sudo chmod +w -R /opt/android-sdk-linux – david Oct 15 '16 at 02:44
  • First we have to run studio.sh from bin directory using sudo then only the write permission is reflected. – dev_ry Oct 26 '17 at 05:32
8

I did set the group of /opt/android-studio (and /opt/android-sdk) to users and added write permission to the group.

In my case, the group users existed already. But as hint:

sudo addgroup users

I had to add my user to the users group:

sudo adduser $USER users

Then set the group of the directory:

sudo chown -R root:users /opt/android-studio

Because updates need to write files:

sudo chmod -R g+w /opt/android-studio

I used this instructions once, I hope i did not forget something

edit: This way, files shall not be too wide accessible, but still usable by selected users

1

I had a similar problem with Rubymine.

sudo chown -R $USER:$USER /opt/Rubymine

worked for me too, but it can be dangerous changing permissions in system folders. Probably better just to run the installation once as root to allow updating. eg.

sudo updatedb && sudo locate rubymine.sh
sudo /path/to/rubymine.sh 
  • Me too! But when I try your solution, it asks for license information again, so I'm not sure what to do at that point... put it in again? I don't want to mess up my license terms... – mltsy Jun 14 '17 at 19:10
  • I'm not 100% sure I would consider /opt a system folder, despite it's "official" categorization as such. It's not in the same category as /usr, /etc, and the like. Its design is to be a central repository for app installations that are accessible to any user. To this extent, it fails miserably unless (IME) unless /opt is simply opened up to the universe, which I've been forced to do. Very unsafe. But I've basically had it up to ^^^ here with fighting my own system during development and have learned the very hard and expensive way that not doing so yields a miserable waste of my time. – tgm1024--Monica was mistreated Oct 11 '20 at 01:34
-1

I was getting the same error. Running following command from terminal solved the problem.

sudo chown -R $USER:$USER /opt/idea-IC-173.4548.28/

You don't need to be in same directory in order to execute the command.

abu_bua
  • 10,783
Tahirhan
  • 111
-1
sudo chmod -R 777 your_android_studio_location_path/

For example (in my Ubuntu 16.04):

sudo chmod -R 777 /home/igor/Android/
  • 7
    Setting file permission masks to 777 is almost always bad advice. -1 – David Foerster Sep 13 '16 at 20:34
  • Its bad advice, but for now it worked so I upvote. – david Oct 15 '16 at 02:45
  • 2
    @david 777 means anyone (including anyone through internet) can access, modify and delete the file. "it worked" is not a good excuse to open such a critical vulnerability to your system. – Mostafa Ahangarha Apr 21 '17 at 11:47
  • @david Smashing your PC to bits, going to the shop and buying a new one, then installing the latest version of Android Studio on it would also "work" but is bad advice and shouldn't be upvoted. The point is there are often multiple ways to "solve" a problem, some of which are the "wrong" way and some are the "right" way. This answer is almost certainly the wrong way. – Jon Bentley Feb 18 '19 at 19:46
  • Upvoted back up 1. Dangerous? Yes. But so is the crazy expense of chasing down permission problems endlessly with app after app when all I want to do is develop. Would I do this on a server machine? No. Have I learned the hard way to simply open up /opt to the universe? Yep. It solves a very expensive problem: losing my time. The risk is absolutely worth it, and being a purist here is just not helpful. Good grief, I've even run into trouble with Intellij Idea in /opt with their plugins when /opt was at default permissions. – tgm1024--Monica was mistreated Oct 11 '20 at 01:40