Created
June 13, 2016 19:52
-
-
Save CyberPunkCodes/38e11f663bbb5ca7e49e548b5bec83ab to your computer and use it in GitHub Desktop.
My OSX Composer Install Guide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create a new directory in /usr/local for composer, and setup directory for downloading the installer. | |
-> cd /usr/local | |
-> mkdir composer | |
-> cd composer | |
-> mkdir setup | |
-> cd setup | |
Inside the setup directory, we are going to follow the instructions to download Composer. | |
(pwd = /usr/local/composer/setup) | |
-> php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
-> php -r "if (hash_file('SHA384', 'composer-setup.php') === '070854512ef404f16bac87071a6db9fd9721da1684cd4589b1196c3faf71b9a2682e2311b36a5079825e155ac7ce150d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" | |
-> php composer-setup.php | |
-> php -r "unlink('composer-setup.php');" | |
NOTE: The above is just a demo, the SHA would be different, so follow it from here: https://getcomposer.org/download/ | |
You should now have `composer.phar` inside the setup directory, and the `composer-setup.php` file was deleted. Lets move composer to `/usr/local/composer`. | |
(still inside setup directory: /usr/local/composer/setup) | |
-> mv composer.phar /usr/local/composer/composer.phar | |
-> cd .. | |
Now composer.phar is in /usr/local/composer | |
We need to make a sym link so it can be found :) | |
Lets go to /usr/local/bin (this is where the link will be made) | |
-> cd /usr/local/bin | |
-> ln -s /usr/local/composer/composer.phar composer | |
Test it! Go to a random directory, such as: /Applications/XAMPP/xamppfiles/htdocs | |
-> cd /Applications/XAMPP/xamppfiles/htdocs | |
-> composer --version | |
-> Composer version 1.1.2 2016-05-31 19:48:11 | |
Done :) | |
Why? | |
Instead of installing composer itself into /usr/local/bin, we want to make a symlink. This is how many other apps are done. If I look how Git was installed, it has it's real directory as /usr/local/git with a symlink to it in /usr/local/bin. | |
If I look in /usr/local/bin, I see that Git, NPM, Mongo, Grunt, and many others are all symlinks. Also, if something goes wrong, and we clear out that dir while trying to uninstall everything, we can keep composer. You would manually have to clean out /usr/local completely, or specifically delete /usr/bin/composer. | |
This makes it easy to update composer and safer from accidental distruction. It also helps ease my OCD, I hated composer being the only app/file in the bin dir! | |
Worst case senario, is you have to re-create the symlink to composer if it was deleted in /usr/local/bin somehow. Even if it was deleted, you could still do `php /usr/local/composer/composer.phar whatever` until you re-made the symlink. | |
PS: This Gist is for my personal reference. I may delete it later, but I added some explanation just in case someone else stumbled upon this :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment