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

Ruby Ruby Foundations Methods Instance Methods

Waiting on the side of the tracks

What is the function of the "subl" command in the code written at 0:51 to 1:06 in the video at this link:

Instance Methods ?

When I try to execute this command in my terminal, it says "-bash: subl: command not found".

4 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

The subl command the instructors use is a shortcut they have created to launch Sublime Text 2 (their recommended text editor) from the command line. In the Unix world the command is called alias and can be created using:

~$ alias customCommand='orignalCommand' so, if you did alais subl='path/sublime_text' it would create an alias named "subl" pointed to sublime_text. Doing this from the command line only allows you to use this alias during your current login session. To create a permanent alias you can edit .bashrc and put the alias command in there.

Ken. Since I don't really know how to post replies properly, this one post-dates the one below. I'm posting here in hopes that you will be notified and read my message.

I am still unable to recreate the sublime alias. I've searched OS X Command Line, and Terminal 101: Creating aliases for Commands to no avail.

I did manage (in only 6 hours!) to get it to work, sort-of, by placing a copy of Sublime Text 2 in the same folder as the file I wanted to run, and using "ruby ~/Source/methods/loops-1.rb" in the Terminal. But I'm not happy with that.

If this message reaches you, and you can see how to put me on the right track, I would very much appreciate it. At any rate, thanks for your help so far.

p.s. The default text editor seems to be Xcode. I prefer TextMate. If I use the touch command to create a file, then open it, it opens in Xcode. How can I make TextMate the default text editor?

Ken. Thanks for your response. Sounds like sound advice.

The terminal seems to accept my command to establish an alias: Richards-Mac-mini:~ ricstr$ alias subl=Macintosh_HD/Applications/Sublime_Text_2

And I am able to make a directory and switch to it: Richards-Mac-mini:~ ricstr$ mkdir -p Source/methods Richards-Mac-mini:~ ricstr$ cd Source/methods

And even create a file: Richards-Mac-mini:methods ricstr$ touch simple_methods.rb

But this is the result: Richards-Mac-mini:methods ricstr$ subl simple_methods.rb -bash: Macintosh_HD/Applications/Sublime_Text_2: No such file or directory Richards-Mac-mini:methods ricstr$ subl simple_methods.rb

What am I doing wrong?

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Richard;

Full disclaimer here, I use Windows and Ubuntu Linux much more frequently than Macs, so take what I say for what it is worth. :)

In Ubuntu, here are the steps I took:

1) From the command line, create an alias: alias subl='/home/username/"Sublime Text 2"/sublime_text'

The double quotes were for the folder in which Sublime Text is located and the folder name contains spaces. The file was named sublime_text so I didn't have to use additional quotes.

2) Once I was able to get the alias working for a single session I added the alias to the ~/.bashrc file. In reading about OS X, it seems that the file you would need to edit is ~/.bash_profile. I believe the command in OS X to edit it would be: nano ~/.bash_profile

That's how it worked for me, I would suggest working with the alias subl="" command until you get the path correct to the sublime_text application file. Not sure what it is actually called for Macintosh.

Post back if you have additional questions and I'll see what additional assistance I can be.

Ken

Antoine Boillot
Antoine Boillot
10,466 Points

Hi all,

I had the same issue with the "subl" command. I typed the following and it worked fine for me then :

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/.rvm/bin/subl

Cheers,