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?
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
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 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 want to extract the software with the Archive Manager, you'll have to run the Archive Manager as root, just as the
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.
gksudocommand, you can get it by installing the
gksupackage in the Software Center. (Or you can use one of the other ways to run graphical applications as root.)
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
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.
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
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
Extract the files to some folder in your home folder or to a folder in
/tmp. Then either of these commands:
sudo mv ~/yourfolder /opt sudo mv /tmp/yourfolder /opt
You don't have permission to write to
/opt as a normal user. Only root can do that.
mv moves the files and
sudo tells your computer to do it as root. You'll have to enter your password. Note that you won't see your password nor will you see dots, stars, whatever. Just type your password and hit Enter.