Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to open a folder in desktop as root and install .jar file in that folder.

I have a ".jar" file in desktop that I need to open it as root user but I want to copy that file into a folder in desktop and then open it as root user. How can I access .jar file in that folder via terminal?

How can I do that?

share|improve this question
Why do you think you need root privileges for that? You can create the folder, write a script which runs something like java -jar file.jar (make the script executable), and then add the folder (which contaings your script) to your PATH in ~/.bashrc. – edwin Jun 28 '13 at 18:39
What you describe should not need root privileges. Please edit your question and explain why. What do you mean by install .jar file? What happens when you type java -jar file.jar or sudo java -jar file.jar? – user68186 Jun 28 '13 at 18:41
I have a ".jar" file in desktop that I need to open it as root user but I want to copy that file into a folder in desktop and then open it as root user. – Alex Jun 28 '13 at 18:49
up vote 1 down vote accepted

If I understand correctly this is what you have:

  <other files>

And you want to run freedom.jar as root.

If you want to do it via the terminal

Just open the terminal (Ctrl+Alt+T) then

cd ~/Desktop/freedom-folder
sudo java -jar freedom.jar

If you want to have a launcher for yourfreedom in the Dash

1: Open a terminal

Run the following commands:

mkdir  ~/bin
cp  ~/Desktop/freedom-folder/freedom.jar  ~/bin
sudo  apt-get  install  gksu

The first two lines will create a folder called bin in your home folder and move your .jar file into it. The last line is to install gksu a GUI frontend for su.

2: Open GEdit Text Editor

Write the following script:


gksudo  java  -jar  ~/bin/freedom.jar

Save it to the bin folder you've created in your home folder. I will assume you've named this script as freedom-as-root without any file extensions.

Now, still in GEdit, click File -> Open... (or click the folder icon). In the file selection dialog, navigate to your home folder and type Ctrl+H to make the hidden files visible. Open .bashrc. Go to the last line of this file and add the following new line:


Save it. (This line in ~/.bashrc adds ~/bin to the search path for executables.)

Create a new file and add the following to it:

[Desktop Entry]
Name=Your Freedom (with root privileges)

Save it in your home folder as freedom-as-root.desktop. (Instead of your-username make sure to type your actual username!)

3: Open a terminal again

Before, opening the terminal download this icon, by clicking the image and Save as... or the like. Save it as freedom.svg to your home folder.

(If you wish you can get some other free/libre icon from the internet, Wikipedia is a good source for these.)

Go to a terminal again and type:

chmod  +x  ~/bin/freedom-as-root
mkdir  ~/.icons
mv  ~/freedom.svg  ~/.icons
mkdir ~/.local/share/applications
mv  ~/freedom-as-root.desktop  ~/.local/share/applications

4: See if this worked

Just open the Dash and type your freedom to see if there were any problems. The icon should appear in the Dash, and when you click it gksu should ask for your password.

Due to an extra step in part (2), now you can also type freedom-as-root in the terminal and it will be enough to run yourfreedom with privileges.

Hope it helps.

share|improve this answer
Edwin thank you very much, your answer helped me. Edvin if I want to have a launcher for this in the Dash what should I do? – Alex Jun 29 '13 at 12:21
I've edited my answer to include how to add it to the Dash. – edwin Jun 29 '13 at 17:53
Edvin I fallowed your commands one by one carefully without any error, but when I type "your freedom" in DASH, a white paper without your ".svg" icon is apeared that is inactive. Where am I wrong? – Alex Jun 30 '13 at 14:18
Please check the following: (1) ls -l ~/bin shows a line containing -rwx****** freedom-as-root (where the asterisks don't matter) and another containing freedom.jar. (2) ls ~/.local/share/applications shows the file freedom-as-root.desktop. (3) ls ~/.icons shows freedom.svg. And (4) in ~/Desktop/freedom-folder there aren't any other files related to yourfreedom (if this is the case please copy them to ~/bin and check again). – edwin Jun 30 '13 at 14:51

fill in your password

cd your-directory
cp path-to-jar/file.jar ./
sudo -k


gksu nautilus

then you can do it graphically. That said, why do you think you need to be root to install a jar in you own home folder?

share|improve this answer
What does the command sudo -k? – Lucio Jun 28 '13 at 18:39
It makes sure that you have to type your password again next time you use sudo ( just to be safe actually). – hetepeperfan Jun 28 '13 at 18:41
I use this command to open .jar file in desktop:1) cd ~/Desktop 2)~/Desktop$ sudo java -jar freedom.jar. But I want to copy .jar file to folder in desktop, and then open it as root. – Alex Jun 28 '13 at 18:52
This is the proper answer to the original question. But you @Alex, may wish to reword your question in order to say what you mention in your last comment: You "want to copy .jar file to folder in desktop, and then open it as root". We must say that copying the file as root WON'T allow you to open it as root by simply double clicking on it. Your original question seems different than your actual needs. – Geppettvs D'Constanzo Jun 28 '13 at 19:01
ok. I have an antifilter program with Yourfreedom name (freedom.jar). I need to run freedom.jar file as root to enabling ECHO mode in the yourfreedom configuration. My .jar file is in desktop, but I have copied the .jar file into a folder in desktop and now I want to open .jar file via terminal as root. – Alex Jun 28 '13 at 19:12

Run gksudo nautilus DIR (DIR being the directory the file is stored in) to open the folder as root.

share|improve this answer
No one should not use sudo graphically use gksu as I mentionned above. – hetepeperfan Jun 29 '13 at 13:04
Sorry. That was an accident. Thanks for the reminder. – Dillmo Jun 29 '13 at 13:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.