Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Digital Literacy

change Linux to run a file without having to enter the path

I am doing the Building Websites with PHP course and am installing Composer on my computer (Linux Mint). I followed the download instructions to install the program globally, but it did not work. The commands were:

curl -sS https://getcomposer.org/installer | php

mv composer.phar /usr/local/bin/composer

I am supposed to be able to run: composer init to create the JSON file, but I have to enter:

php /usr/local/bin/composer/composer.phar init

How can I make it so I do not have to enter the entire path to get composer to run?

4 Answers

I figured out the problem. The file has to be in the /usr/local/bin folder, not in a subfolder. I don't know why the alias doesn't work.

The alias wouldn't work because you have to register the new bashrc with the system. You either have to log out or run the source command.

Hi Ted,

You should be able to run a command like that by adding it as an alias to a .bashrc file. First, open/create a .bashrc file in your home directory (run this from terminal):

gedit ~/.bashrc

Next, in the file that pops up, type out an alias for the command. The alias command is going to be the word that comes right after alias so you want it to just be composer and then you set it equal to the path for the binary file that it needs to execute:

alias composer='/usr/local/bin/composer/composer.phar'

And then save the file and close it. Restart your terminal. So, now when you run your command, you should only need to type out:

php composer init
or:
composer init

I added the line so now the .bashrc file reads:

alias composer='/usr/local/bin/composer/composer.phar' export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

when I try php composer init or composer init I get the following errors:

When at ~$: could not open input file: composer

When at /opt/lampp/htdocs/composer_project $ No command 'composer' found, did you mean: Command 'compose' from package 'mimme-support' (main) composer: command not found

Can we assign the following an alias?

php /usr/local/bin/composer/composer.phar

If so, then maybe I can add the init or other command after the alias.

You should be able to just add php to the beginning like that. I've never ran composer before, but I've had experience with the Linux CLI.

Same errors

Ah it looks like you have to log out and log back in, and not just close the terminal. Or just run the command:

source ~/.bashrc

I forgot that you have to register the new bashrc with the system.

I think my brain is full. Learning HTML, CSS, JavaScript, Sass, Compass, PHP, Composer, Linux all at once is a lot. lol

Same here! lol