11

I installed the LAMP stack on my Ubuntu 11.04 (Natty Narwhal) with

sudo apt-get install lamp-server^

Now I navigate to /var/www and use

wget http://ftp.drupal.org/files/projects/drupal-7.x-dev.tar.gz

I get the following error.

 --2011-08-03 13:59:00-- 
 http://ftp.drupal.org/files/projects/drupal-7.x-dev.tar.gz Resolving
 ftp.drupal.org... 64.50.233.100, 64.50.236.52 Connecting to
 ftp.drupal.org|64.50.233.100|:80... connected. HTTP request sent,
 awaiting response... 200 OK Length: 2757101 (2.6M)
 [application/x-gzip] drupal-7.x-dev.tar.gz: Permission denied

 Cannot write to `drupal-7.x-dev.tar.gz' (Permission denied).

How do I resolve this error?

I tried to download the same file in the downloads folder, and it went on without an issue. So it seems to be some permission error, but I'm not sure about that or how to solve it.

1

3 Answers 3

26

I believe you need root permissions to write to /var/www. So you should use sudo in front of your command i.e

sudo wget http://ftp.drupal.org/files/projects/drupal-7.x-dev.tar.gz
6
  • this works, but in my desktop, I don't require to use sudo in front of wget
    – Nikhil
    Aug 3, 2011 at 8:57
  • @Nikhil: you might have changed the permissions of /var/www on your desktop. Its not wget which needs sudo but the directory /var/www as only root user has write permissions to this directory.
    – binW
    Aug 3, 2011 at 8:58
  • this might be the case, because I just used tar to unpack the files, and it also required me to use sudo, which was not the case with desktop version.
    – Nikhil
    Aug 3, 2011 at 9:01
  • @Nikhil: tar will unpack the file drupal-7.x-dev.tar.gz and will create few directories and files in the process in /var/www directory. Again as only root has write permissions to /var/www, you need to use sudo to untar the file. If you dont want to use sudo you can either switch to root prompt using "sudo -i" or change the permissions on /var/www directory to allow writes to your username but I WONT RECOMMEND any of these methods. Stick to using sudo, its safer.
    – binW
    Aug 3, 2011 at 9:05
  • ok, I got it, I also found comment by Lekensteyn helpful. Using sudo all the time is really annoying and painful at times.
    – Nikhil
    Aug 3, 2011 at 9:20
1

You don't need to sudo every time you get some error; this does not fix the problem. The problem is, as the error says that you don't have "permission" to "write" to that directory.

Of course, root has the right to do anything, which the primary goal of many viruses happen to be. I have chmod 755 & chmod 766 to get the same error with wget, cp & mv.

What worked was to own the directory being worked in so don't have to sudo often:

sudo chown <username> <directory>

After this, ordinary commands work normally.

Tested on Ubuntu 16.04.7 LTS

0

Changing the ownership chown of the directory and sub directories -R fixed the error for me. In ubuntu 20.04 LTS version. I ran the following command and this permission denied error was fixed.

sudo chown -R $USER:$USER /var/www and sudo chown -R www-data. /var/www

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .