You do not have permission to extract to this folder

I am running Ubuntu 16.04 LTS.

I am trying to extract a tar.gz file using Archive Manager.

When I try to extract to /opt it says "You do not have the permissions to extract to this folder".

How can I overcome this problem?


Solution 1:

Most software shouldn't be installed this way.

First you should make sure /opt is really where you want to put it, and that you really want to install the file from that archive at all, rather than another source.

/opt is usually used for software that is not part of Ubuntu and not installed using Ubuntu's package manager (since when it is, it usually goes in multiple subdirectories of /usr.). In addition, most often it's used for software that is provided as pre-built binaries, and not software that you're building from source code (since that usually goes in multiple subdirectories of /usr/local).

A lot of software that is available as pre-built binaries is also packaged officially for Ubuntu (see also this question), is packaged in an unofficial PPA, or is provided in a downloadable .deb file. Those methods are often preferable (usually in that order) to installing unpackaged pre-built binaries.

If you're sure you want to unpack the archive to /opt...

If you know you want to install software in /opt, you should check if there are official guidelines, specific to that application, for how best to do so. The developer or vendor of the software may have specific recommendations that cover installation issues beyond how and where to unpack the files.

With all that said, if you know you want to extract it in /opt, you can do this in the Terminal (Ctrl+Alt+T) by running:

cd /opt
sudo cp /path/to/filename.tar.gz .
sudo tar xf filename.tar.gz

You would replace the italicized /path/to/filename.tar.gz with the actual location and filename of the file you want to put in /opt and extract. Dragging a file from Nautilus (the file browser) into the Terminal application will automatically paste its full path on the current line, which can make things easier.

If you feel you must use the Archive Manager to extract the file...

If you want to extract the software with the Archive Manager, you'll have to run the Archive Manager as root, just as the cp and tar commands in the above example were run as root. It's widely recommended to avoid running graphical programs as root unless you really know you want to--often they are not designed or tested with such use in mind.

If you really do want to run the Archive Manager as root, you can do so by pressing Alt+F2, typing the command gksudo file-roller and pressing Enter. You should be very careful after doing this -- for example, you can access and overwrite important system files. You should make sure to close the program when you're done so you don't later forget that it's running as root (rather than as your user) and use it for something else where it's not needed.

  • If you're using Ubuntu MATE, run engrampa instead of file-roller.
  • If you find you don't have the gksudo command, you can get it by installing the gksu package in the Software Center. (Or you can use one of the other ways to run graphical applications as root.)
  • Of course, you can avoid all this complexity by unpacking archives with sudo tar... in the Terminal (see above) when you need to do as as root, and reserving the Archive Manager for the more typical cases when you want to extract an archive without elevated privileges.

I don't recommend doing it this way, and this section is provided mainly for completeness or in case you're sure you want to run the Archive Manager as root. You do not need to run the Archive Manager as root to install software, even if you choose to install it from a .tar.gz archive file and choose to put it in /opt.

General information about manual installation from downloaded archives:

Often it's better to install software through the other ways listed, with links to guides, in the first section of this post. However, if you are going to install software by unpacking a .tar.gz (or similar) archive, I recommend you read How do I install a .tar.gz (or .tar.bz2) file? before proceeding.

Solution 2:

I highly recommend Eliah Kagan's answer

UTF-8's answer also suggests a good approach

You can overcome this problem by launching the archive manager program as root

sudo -i
file-roller 2>/dev/null &

(if using Ubuntu MATE, the program is engrampa instead of file-roller) Navigate to the file, extract to your desired location, and back in the terminal, don't forget to

exit

when done, to drop privileges.

Also worth knowing, you can extract to a target directory with the -C option to the tar command, for example, if the archive is in your Downloads directory:

cd Downloads
sudo tar xvfz name-of-your.tar.gz -C /opt