150

I created a new Laravel project. When I go to the terminal to install the dependecies composer displays the following warning:

Cannot create cache directory /home/w3cert/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache.

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68
Karthik
  • 5,589
  • 18
  • 46
  • 78
  • looks like composer doesn't have write permission in /home/w3cert/.composer/cache/ folder – Amir Bar Mar 08 '16 at 18:00
  • 2
    This may also happen if you run `sudo composer self-update` on Linux, since the `~/.composer` directory will be owned by `root`, afterwards. – caw Mar 09 '17 at 02:39

4 Answers4

291

When you installed composer pretty sure you used $ sudo command because of that the ~/.composer folder was created by the root.

Run this to fix the issue:

$ sudo chown -R $USER $HOME/.composer
Jim M
  • 4,261
  • 1
  • 18
  • 15
242

Change the group permission for the folder

sudo chown -R w3cert /home/w3cert/.composer/cache/repo/https---packagist.org

and the Files folder too

sudo chown -R w3cert /home/w3cert/.composer/cache/files/

I'm assuming w3cert is your username, if not change the 4th parameter to your username.

If the problem still persists try

sudo chown -R w3cert /home/w3cert/.composer

Now, there is a chance that you won't be able to create your app directory, if that happens do the same for your html folder or the folder you are trying to create your laravel project in.

Nesar
  • 5,599
  • 2
  • 22
  • 21
  • 18
    I've encountered this a couple of times, but just realised that this may be a consequence of running self-update as root: $ sudo composer self-update , which may have been the cause of why the ~/.composer folder and all its contents change owner. Just chown -R your ~/.composer back to yourself – andkrup Oct 14 '16 at 08:42
  • 11
    I am sure this problem started to generate right after i did `sudo composer self-update` – Pratik Jul 14 '17 at 08:06
  • 5
    BTW, chown changes owner, to change group too, you have to do `w3cert:w3cert` (`[OWNER][:[GROUP]]`) – Pratik Jul 14 '17 at 08:09
  • This helped me in creating project. After executing first two commands, everything went fine. – rahul Oct 08 '18 at 19:27
  • I went to the `.composer/` directory and `sudo chown $USER -R /cache` that helped. – saggzz May 05 '19 at 10:08
  • @andkrup: Just chown -R your ~/.composer saved my life! And I did sudo composer too... – Marcelo Scofano Diniz Jul 21 '19 at 04:57
  • I'm getting this error in a window, Xampp server is there any solutions for it? – Dilip Hirapara Oct 12 '19 at 06:09
5

Change ownership of your .composer directory:

sudo chown -R $USER $HOME/.composer

$USER is your username and $HOME is your home directory.

LobsterBaz
  • 1,752
  • 11
  • 20
Shrip
  • 101
  • 1
  • 6
  • `chmod 777` is always a bad idea. And to get your username simply use the environment variable `$USER`. I've edited your answer accordingly. – LobsterBaz May 16 '21 at 18:17
2

Use this command:

sudo chown -R $USER ~/.composer/
Oppa
  • 21
  • 2