Sublime Forum

Subl command in termial not linking

#1

I looked at the documentation here:
http://www.sublimetext.com/docs/2/osx_command_line.html

I am not able to get subl command to work in terminal for Mac OS High Sierra. I get a “No such file or directory” error. Any suggestions would be very much appreciated. Thank you!

1 Like

#2

Try the instructions for version 3 here: http://www.sublimetext.com/docs/3/osx_command_line.html

0 Likes

#3

As I mentioned in the original post, those instructions are what I was using. I am looking for other ideas, it seems that perhaps, with High Sierra, they do not have a local bin?

0 Likes

#4

To be fair, you linked to instructions for Sublime Text 2 and @ig0774 linked to instructions for Sublime Text 3. For clarity, where exactly do you see the error, when you try to create the link, when you try to run subl?

I’m not running that version of MacOS on my MacBook, but the location of the link is less important than whatever location you choose being in the PATH, so worst case scenario make the link somewhere else and then ensure that location is in the PATH.

0 Likes

#5

When I try to open a file from terminal:
MBPro:~ tmbpro$ subl test.c
-bash: subl: command not found
MBPro:~ tmbpro$

When I try to make symblink:
MBPro:~ tmbpro$ ln -s “/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl” ~/bin/subl
ln: /Users/timothyparrish/bin/subl: No such file or directory
MBPro:~ tmbpro$

0 Likes

#6

The first error is because the subl command can’t be found, which is because the second command is failing, You can add the directory by saying mkdir ~/bin in the terminal, but you also need to add that to the PATH as well or it still won’t work.

Since the instructions say:

Assuming you’ve placed Sublime Text in the Applications folder, and that you have a ~/bin directory in your path, you can run:```

I would imagine that this folder isn’t necessarily there by default or in the path and you’re meant to select a directory that is in the path (or put one there).

0 Likes

#7

Thank you for your help! That at least let me run the command:
ln -s “/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl” ~/bin/subl
However, it still will not reference sublime text if I use subl in the terminal. Do you have any other ideas?
I did also verify that is the same way sublime text is labeled in my applications file.

0 Likes

#8

If the ln works but subl doesn’t, then the ~/bin folder isn’t in your PATH, so the shell doesn’t know to look there.

To fix that you need to modify your PATH environment variable to include the bin folder in your home directory so that it knows to look there. You can verify this by using the command which subl in the shell; if it says nothing at all, then it can’t find subl, otherwise it will tell you where it’s found.

Assuming your shell is bash (it is on my MacBook but I prefer bash so I don’t know if there are any alternatives), you can create or edit the file .bashrc in your home directory (note the leading dot) and then add the following line:

export PATH=$PATH:$HOME/bin

This modifies the path by changing it’s value to the existing path plus a new entry for a folder named bin in your home directory.

The .bashrc file is only loaded and executed when a new interactive shell is opened, so for this to take effect you need to open a brand new terminal window; it won’t have any effect in existing terminals. As a shortcut for testing purposes, entering the command bash will start a new shell inside of an existing shell.

If your shell isn’t bash, then there is some similar series of steps that you would need to take, but exactly what they are depends on the shell you’re using.

1 Like

#9

Hi, I am new to the forum . I am having the same issues as CrimsonScorpion27 who started the thread. How do I:

  1. find the .bashrc file, and
  2. edit it with export PATH=$PATH:$HOME/bin
    Thank you in advance for your help!
0 Likes

#10

It’s just a regular file in your home directory with a name of .bashrc (the leading . is important). Unix type systems generally hide files that begin with a dot (i.e. dotfiles) from regular file listings and MacOS does this as well in Finder unless you run various arcane commands.

Probably the easiest thing to do would be to open the Sublime console with View > Show Console, then enter the following command and press enter:

window.open_file("~/.bashrc")

If you already have a .bashrc file, then this will open it for you to edit. If you don’t have one the console will tell you that it was unable to open the file, but it will create a new empty tab with the appropriate name, so you can just make your modifications and save the file.

To make the changes just copy that full line (export and all) from the post above and add it to the file. If you’re in doubt where to add it, make it the last line the file (or the only line, if there is not already any content in the file).

1 Like

#11

Hi @OdatNurd. Thank you again for the information. I followed your instructions, saved the new .bashrc file in Sublime, closed Sublime, restarted the terminal, and ended up with this:
Previously, I did not even have a /bin/subl, so I created it according to information I found on stack overflow.
Also, I found this potential issue about system integration protection on MacOS: https://www.imore.com/el-capitan-system-integrity-protection-helps-keep-malware-away
In the terminal, I ran: csrutil status. It is enabled on my Mac.
Is the SIP issue causing this? What is the work around? Any other suggestions? Thank you again for your help!

0 Likes

#12

The first thing to do is run the command echo $PATH in the console to see if it includes the path /Users/imacminette/bin somewhere inside it (that’s what $HOME/bin would expand to in your case)., although I assume the answer is no.

There next thing to try would be to run the command bash, then try the subl and/or echo $PATH commands again to see if restarting the shell has any effect. While doing that, take note of anything that gets printed when you execute bash, which may point to problems.

0 Likes

#13

OdatNurd: Thank you so much! I not only got my problem solved with your help, I got to experience the cool stuff that the .bashrc file can do and geeked out my command prompt and colors as well…
Other new users should look to
Part 1:


Part 2:

Thanks again!

1 Like