Composer Self-Update Error Exception “Permission Denied” when calling rename()

So, whenever i run composer self-update or composer selfupdate I get the following error:

Output of the Composer Error

[ErrorException]
rename(/Users/jrobinson/.composer/cache/composer-temp.phar,/usr/local/bin/composer): Permission denied

I’m not too sure what’s going on. I THINK i may had screwed up my .bash_profile file up. I wasn’t having this issue prior to installing MySQL on my machine, and updating the first line in my .bash_profile.

I have looked at other articles, and I have tried reinstalling using the getcomposer.org commands on their download page. None of these solutions have fixed my problem. So please don’t mark this as a repeat question as none of the solutions on SO have helped me solve this issue.

Here is my .bash_profile file contents.

export PATH="~/.composer/vendor/bin:$PATH:/usr/local/mysql/bin"
export EDITOR='sub -w'

Here is the ls -la command run in the /usr/local/bin folder.

Output of the ls la command in /usr/local/bin

Goal

Be able to run the composer self-update command and the mysql command from my terminal at the end of all this.

Answer

It looks like Composer is installed in /usr/local/bin, so you probably did that as root. To update it, you also need to be a root – try with sudo:

sudo composer self-update