There may be two things going on here:
Ownership: Files located in the user's home directory may be owned by root
, when they should be owned by the user.
Location: Files may be located in root
's home directory (/root
) when they should be located in the user's home directory. (The OP figured this out, but accepted this answer, so I've augmented it to include this for the benefit of others experiencing this problem.)
Fixing Ownership
sudo eclipse
runs Eclipse as root
, but it still uses your (that is, not root
's) home directory to save its files. Since it runs as root
, files it creates are owned by root
, and users other than root
cannot access them. The result is that if you've run sudo eclipse
once, Eclipse can only be run via sudo eclipse
afterwards, until the problem is fixed.
This is not actually a permissions problem, it is an ownership problem, and the solution is to retake ownership on the affected files and folders. It's usually safe to be the owner of all the files inside your home folder. So, with Eclipse not running, run this command:
sudo chown -R $USER:$USER ~
$USER
will be expanded by the shell to your username, so you can run that command exactly as-is. Alternatively, if you want to replace $USER
with your actual username (in this case, engine
), that works too.
How that command works:
chown
is the command for changing ownership on files and directories.
~
is shell shorthand for your home directory.
-R
means it's not just changing ownership of your home directory, but that the operation is to apply recursively, to all files contained anywhere within your home directory.
- The first
$USER
means you will be the owner of the files. The second $USER
(after the :
) means your user's group (the group created with your user account, to be the default group-owner of your files) will be the group owner.
For future reference:
- If you must run a graphical application as
root
, you should use a graphical sudo
frontend like gksu
/gksudo
or kdesudo
. This sets the $HOME
environment variable to /root
--root
's home directory. (It also makes a copy of ~/.Xauthority
.)
- However, it's best not to run complex applications like Eclipse or Firefox as
root
at all, for security reasons. Some graphical utilities must run as root
to work, but Eclipse is not an administration tool, and you should never need to run it as root
. If you do, something is wrong.
Fixing Location
As @Engine wrote:
The problem wasn't the whole directory, but only the folder /tools
in
android-sdks
. I copied it from the root folder and then I gave my
user the ownerships rights with:
chown -R $USER:USER ~
That is to say that, when eclipse
had been run as root
, it had (at least at some point) used root
's home directory (not the user's home directory), and the Android SDK had been stored inside root
's home directory.
- Either that, or the Android SDK could have been manually installed as
root
beforehand.
For the benefit of others with this problem:
The tools
folder can be copied from inside /root
with:
sudo cp -R /root/android-sdks/tools ~/android-sdks/
Or you can move the tools
folder (rather than copying) with:
sudo mv /root/android-sdks/tools ~/android-sdks/
Then fix ownership as described above. Or, just for the relocated tools
folder, with:
sudo chown -R $USER:$USER ~/android-sdks/tools