Cannot get subl command working for ST3 on OSX - macos

I am trying to get the Subl command working on my Mac OSX Mavericks. I have ST3 in my root applications folder.
When I run the line below, I also run it with sudo and get the same message.
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
In the terminal I get the following error
ln: /Users/username/bin/subl: No such file or directory
I double checked to see if it was working or not with
subl --help
but get the following error
-bash: subl: command not found
I am trying to get this to work so I can use it with Git and open file with sublime from there https://help.github.com/articles/associating-text-editors-with-git#using-sublime-text-as-your-editor
My .bash_profile looks like the following
export PATH=/usr/local/git/bin:$PATH
export PATH="/usr/local/bin:$PATH"
export EDITOR='subl -w'
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
fi
Can anyone advise how to fix this problem,
Thanks

Most likely the issue is that you don't have a /Users/username/bin directory in the first place, so your ln command trying to create a symlink isn't working. Secondary to that, even if ~/bin did exist, it's not part of your PATH, so the subl command won't ever be found.
To make things much easier for you, just create the symlink in /usr/local/bin. It (hopefully) already exists, and is already in your PATH. Just run
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
and you should be all set.
In response to your comment: There are 2 commands here - ln, which creates a symlink, and export, which just creates an environment variable (PATH is a special environment variable that contains the list of directories searched for commands when you enter something in Terminal).
When you create a symlink, the entire directory tree needs to exist before the link will be created. So, while /Users and /Users/username already existed, /Users/username/bin did not, so the ln command failed, regardless of whether sudo was used. In order to create the bin directory in your home directory (also known as ~), you would first have needed to run mkdir ~/bin, then create the symlink with your first ln command (the one without the sudo). Next, you would have needed to add ~/bin to your PATH environment variable by replacing the first two lines in ~/.bash_profile with
export PATH=~/bin:/usr/local/bin:/usr/local/git/bin:$PATH
However, since /usr/local/bin was already in your PATH, the easiest solution was to create the symlink to subl there, instead of creating a new ~/bin directory, making the symlink, editing ~/.bash_profile, then restarting your shell.

I also have this requirement. I use alias instead of those symbolic link method. It is rather easy and here is how.
Step1: Open ~/.bash_profile, add below line into it then save and close it.
alias subl='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
Step2: execute source to make the alias setting take effect.
source ~/.bash_profile
Now you can use command subl following by a file or directory path to open them, enjoy!

Related

Error trying to make symlink to subl - can't find directory

I am trying to create a symlink to subl, but I am having issues. The instructions read: "Assuming you've placed Sublime Text in the Applications folder, and that you have a ~/bin directory in your path, you can run:"
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Initially, I got /Users/User/bin/subl: No such file or directory.
So I tried making the directory with mkdir /usr/local/bin and running a modified version of the above command:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
That worked, but when I ran subl --help this error popped up:
-bash: subl: command not found
I also tried mkdir ~/bin. No luck. I'm also concerned because the instructions say Sublime should be in the applications folder, which it is in Finder, but not under tbecks/Applications. Thank you for any help!
The first ln command you ran used /Applications/Sublime Text.app, but the second used Sublime Text 2.app. Since you tagged the question sublimetext3, I'm assuming that's the version you're using. Here's what you need to do to get the symlink working. First, verify subl is in the correct spot:
ls -l /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl
If you installed Sublime in the correct spot, something like this will print:
-rwxr-xr-x# 1 mattdmo admin 158192 May 11 21:47 /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl
Now that we know where the original subl is, we can fix the mistake you made using the ST2 path:
rm /usr/local/bin/subl
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
Next, we'll see if /usr/local/bin is in your PATH variable:
# reload bash's hashmap of executables
hash -r
# find subl, hopefully
which subl
If /usr/local/bin is in your PATH, the which command will print
/usr/local/bin/subl
If it does, you're good to go. If it doesn't, we'll need to add it to your path. Unlike another answer says, you should never mess around with anything in /etc unless you know exactly what you're doing. Instead, we'll make the change in your personal bash startup file. Depending on which version of OS X you're on, this file could vary. Go to your home directory by typing
cd
then run
ls -al
to show all of the files and directories, even the "hidden" ones that start with a dot/full stop .. You are looking for .bashrc or .profile. If both exist, or if neither exist, use .profile. Run
/usr/local/bin/subl ~/.profile
# or .bashrc
and add the following line at the bottom:
export PATH=$PATH:/usr/local/bin
Save the file and close it. Now, you can restart Terminal and your subl command should be ready to use! If for some reason it still doesn't work, try adding the above line to the other file (i.e., if you just added it to .profile, try adding it to .bashrc and vice versa).
when I ran "subl --help" this error popped up: "-bash: subl: command
not found"
Most likely /usr/local/bin is not in your path.
Add
PATH=$PATH:/usr/local/bin
at the end of your bash configuration file( most likely /etc/bash.bashrc) and then execute the command again or confirm the command is reachable using:
which subl
Edit:
Even better modify the PATH in ~/.bashrc if you wish to restrict subl only for you.

Sublime Text 2 - OS X Command Line

Original Sublime 2 instruction for enabling editor to launch from command line:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
do not work in Mountain Lion.
Create the ~/bin directory if it doesn't already exist:
mkdir ~/bin
Then run the ln again. Make sure that directory is added to your $PATH by adding this to the ~/.bashrc file, creating it if it doesn't exist:
export PATH="$PATH:~/bin"
If you don't use bash, use your manual to figure out how to add a directory to your $PATH variable.
This is actually what the instructions say:
The first task is to make a symlink to subl. Assuming you've placed
Sublime Text 2 in the Applications folder, and that you have a ~/bin
directory in your path, you can run: [snip]
This implies you need to create the ~/bin directory if it doesn't exist, and add it to your $PATH if it is not there already. The above instructions do exactly that.
If you don't like that ugly bin folder in your pretty home folder, you can use chflags to make it disappear from the Finder:
chflags hidden ~/bin
Change target directory to system folder /usr/bin and use sudo for admin rights.
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /bin/subl
I recently ran into this problem on OSX Mountain Lion and then again on Mavericks. This solution worked for me:
Create the bin directory in /usr/local/bin if it doesn't already exist:
sudo mkdir /usr/local/bin
You have to use sudo and enter your password to create the directory because it is inside a system folder.
Setup subl as a command-line command in the /usr/local/bin:
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
The directory /usr/local/bin is already in your $PATH by default, even if it doesn't exist yet, so there is no need to add it to your $PATH. The folder /usr/local is also the folder used for git and homebrew installs, so it makes sense to keep all your local command-line commands in this location.
Maybe its already here, but this one worked like a charm for me:
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

command "subl" from terminal don't work

I am a Mac-newbie (Mountain Lion) and try to set up the "subl"-command for the terminal, like described here:
The first task is to make a symlink to subl. Assuming you've placed
Sublime Text 2 in the Applications folder, and that you have a ~/bin
directory in your path, you can run:
ln -s "/Applications/Sublime Text
2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
But it doesn't work. I have now a folder /bin/ under my user and this folder including a alias. But when I tip in subl --help inside the terminal, I get the error -bash: subl: command not found
Can someone helps me out?
KR & thx, Fabian
Change directories to:
/usr/local/bin
then run this instead:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" subl
I have found the solution now - there was a problem with RVM. The solution is to enter the command
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/.rvm/bin/subl
into the terminal.
That happened to me with Sublime Text 3.
This symlink works for me, only I needed was to change the symlink destination to /usr/local/bin/subl
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Solution source Paul Byrne answer here
Using Homebrew to install Sublime usually creates the correct symlinks automatically.
brew install Caskroom/cask/sublime-text
Subl can then be accessed like:
# Open Sublime at current directory
subl .
The solution chosen for this question is to put the subl symlink in the ~/.rvm/bin folder which is definitely not a generic solution as this directory is part of a program he has installed.
Although any directory in the path will work, the most common solution is to create a bin directory in the home folder, set it in the path by putting export PATH=$PATH:~/bin in .bash_profile and then running the link command as shown in the original question with this new path.
In the past it was common to put the subl symlink in /usr/local/bin but this directory no longer exists in OSX as of version 10.2 and the /usr/local directory is no longer in the default path.
SOLVED for MAC OSX Mavericks!
I found this answer on this GitHubGist:
https://gist.github.com/artero/1236170
Launch Sublime Text 2 from the Mac OS X Terminal
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime
This is the part that I found clarified what many StackOverflow responses have only hinted at, but not explicitly explained:
Now let's do a check to see if everything will run smoothly. Enter this:
open ~/.bash_profile
(In some cases the profile file is named ~/.profile)
You should see at the top of the file a line that starts with: export PATH=
This contains all the directories that will be looked into for executable binaries when you type a command in Terminal. Since we create a symlink to subl called sublime in the /usr/local/bin directory let's check if this directory is listed on that same line.
If it is, perfect. Let's keep going. If not, simply add it like this and save the file:
export PATH=/usr/local/bin:(...)
Note: The '(...)' in this example represents other folders that would be listed on the same line and separated by a colon.
If you don't already have a PATH set in your bash_profile you can type:
export PATH=/usr/local/bin:$PATH
If you had to add /usr/local/bin to your PATH, run the following command before continuing:
source ~/.bash_profile
This will reload your .bash_profile with the newly added directory.
Testing
Open a Terminal window and run:
sublime filename (replace "filename" by an actual file name)
Hope that helps clarify for others as well. Currently (FALL 2014) using Mac OSX Mavericks. Cheers
If you just want the command to open files using sublime text, and you're not bothered to use it as your default editor for all commands, why not just add an alias to your ~/.bash-profile ?
alias subl="open -a 'Sublime Text'"
That will work for opening files and directories
Had the same problem on a MAC with OSX Yosemite 10.10.5, and sublime text 3 Build 3083!
Configuring git to work with the above requirements worked perfectly using:
git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w"
And test if it worked with:
git config -e
It works on Mac OSX 10.8.2, echo $PATH shows subl symlink correctly linked as described in this post. The other suggestions on Sublime Text 2 page seem not work with new Macs
I discovered that there was an alias for subl. Type alias to see all defined aliases. Find the source and comment it out, or use unalias subl to unset.
For .bashrc or .zshrc
alias subl="open . -a /Applications/Sublime\ Text.app"
Catalina's auto-sandboxing seems to broke the subl command.
Use the following alias as an alternative
alias subl="open $1 -b com.sublimetext.3"
After $ subl . did not work for me,
I tried $ bundle exec subl . and it worked.
Solution: type $ bundle exec subl . and it should work. (Obviously, omitting the $)

How do I add ~/bin to my path?

I've been having trouble modifying my path to add Sublime Text 2. I've added a ~/bin directory and run this command:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
The subl link appears in ~/bin. But I need to add the ~/bin directory to my path. I'm fairly new at this, and I don't know where my path is. I've looked around, and found that the likely files are either .profile, .bash_profile or .bashrc
I don't have a .bash_profile. To .profile and .bashrc I added
PATH=$PATH:~/bin/subl
export PATH
Is that the right thing to add? And if so, where should I add it?
When I echo $PATH, I get:
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/bin:/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/bin:/Users/<username>/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/<username>/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
When I type subl, I get:
-bash: subl: command not found
Thanks!
p.s. I had previously installed Macports, which modified my .profile file. Not sure if this has anything to do with it - I now don't know what the default .profile looks like.
I was just as new to this as you, which means I wasn't even sure how to read half the stuff related to modifying PATH. Eventually though I came upon a way to do it that doesn't require you to put subl into the .rvm/bin (since that is for something else) but in its appropriate directory, which is ~/bin.
Go to your terminal and type:
open -a Finder /usr/bin
This will open your Finder to the /usr/bin directory. Once you're there open a new Finder, go to Applications, right click on the Sublime Text icon and go to Show Package Contents, then to Contents, SharedSupport, bin. Copy the subl file and paste it into the other Finder showing /usr/bin
That's it! You should be set to use the command:
subl . (or subl file.name)
Instread of all commented here. You need add symlink to sublime in /usr/local/bin. Its not require a root access. And don't need to create another bin directory.
For Sublime Text 2
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/
For Sublime Text 3
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/
Update for zsh
For some reason, "~/bin" in my path wasn't working when I recently switched from bash to zsh/prezto. I changed it to "/Users/myusername/bin" and it works fine once again. I'll be looking for a reason why and update when I find it. Please comment if you have a better solution.
I know this is an old post, but thought I'd document a solution for anyone else trying to follow the instructions given by sublimetext for working with sublime from the OSX command line verbatim. Update for Sublime text 3 Sublime Text 3 Documentation
1) Create a directory called "bin" in your home directory "~/"
mkdir ~/bin
2) Create a symbolic link to your sublime text 2 app in the new directory you just created
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Update for Sublime Text 3 app path is slightly different:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
3) Follow Ryan Hoffman's instructions on how to easily add to the path in OSX: add to the path on Mac OSX Add the newly created "~/bin" to the path using his technique. Your /etc/paths file will look something like this when you're done (notice ~/bin at the end):
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
~/bin
4) Open a new terminal window to start using subl from the command line.
You don't need to do PATH=$PATH:~/bin/subl. Instead, PATH=$PATH:~/bin is sufficient. That way, you are telling the shell to look into ~/bin for binaries. With your command, you told the shell to look into the "folder" ~/bin/subl for binaries, which doesn't work. Furthermore, you don't need to add the commands in two files. Add them once in your .bashrc. I am not a bash expert, but I can recommend reading this blog post for further explanations of the different startup files.
I'd like to pose an alternate solution to this problem. Use a directory already in your path. Like this:
$ sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
tl;dr
I ran into the same problem in Yosemite (OS X 10.10) where, in a fresh install of the OS, the ~/bin directory doesn't exist and isn't in your path. Yet there are lots of useful places already in your path you could place the symlink to Sublime.
For example here are the items currently in my path (use $ echo $PATH to get a list):
/Applications/Postgres.app/Contents/Versions/9.3/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin:/usr/local/bin
/usr/local/mysql/bin
You can easily modify the script to use a location already in your path by changing the part that says ~/bin/subl to /usr/local/bin/subl
Thus, running the following command will accomplish your goal.
$ sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
You need to first create a symbolic link to /usr/bin. A symbolic link - or SymLink - is an alias or shortcut to a directory. Do as follow:
First, make sure you are in your Home directory using the Terminal command line
cd ~
Create a symbolic link to your usr/bin directory.
ln -s /usr/bin bin
Where ln = create a link, -s = symbolic, followed by the [target diectory] and [name of link]
Test your new link
cd bin
This should take you to your ~/bin - same as /usr/bin. The ~ indicates there's a long path hidden inside.
Now, go back to your Home folder to install the subl command
cd ~
Install the Sublime Text 2 command line tool. I'll be using sudo to bypass any permission blocks.
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
You should be good to go! Test it by simply entering subl as your command line and it should launch Sublime Text 2 from Terminal.
I had been struggling with this problem recently. I realized that the ~ isn't expanded to your home directory in the path. At least it wasn't for me.
This is what I did to make it work.
export PATH=$PATH:$HOME/bin
My subl was linked from the application directory into my ~/bin per some followup instructions I found for brew cask. Unfortunately the path was never updated.
had the same challenge and ended up just creating a .bash_profile file, and adding the path statement directly there. Worked without incident. You may want to also check out Alvin Alexander's sample .bash_profile post (http://alvinalexander.com/blog/post/mac-os-x/sample-mac-osx-bashrc-terminal-startup-file) - I found a couple of other helpful commands that I'll be adding as well.
Simple do it this on the terminal:
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
That is where my Sublime is stored, try to type the path to Sublime because your version may differ.
subl .
Should be working fine.
echo $PATH
and use one of the path already in there. In this example "/usr/local/bin"
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
if the system return No such file or directory
sudo mkdir /usr/local/bin/
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
test if it's working
subl
This is for Sublime Text 3.
Here are the full instructions to do this (for Sublime Text 3):
Please check your System Integrity Protection status by the following command:
$ csrutil status
If it's enabled, please follow these steps:
Boot to the Recovery OS of OS X by restarting your machine and holding down Command + R at startup.
Launch Terminal from the Utilities menu.
Run the following command:
$ csrutil disable
$ reboot
This is due to a security feature of OS X called System Integrity Protection, which will protect against unauthorised access to system locations and processes. So if this feature is enabled, you won't be able to modify the content of /usr/bin.
Create a symlink from /usr/bin to ~/bin:
$ sudo ln -s /usr/bin ~/bin
Create a symlink from the Sublime Text 3 CLI tool to ~/bin:
$ sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl ~/bin
Test it.
$ subl .
following works with me. I have Sublime version 3 and posting it here if someone is looking for help:
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /bin/subl
It seems like in Yosemite the command is actually for Sublime 3, but I may be mistaken:
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/
On MacOS 11, this command worked for me to establish a symlink for Sublime Merge. The main difference seems to be calling ln with the -sv instead of -s:
ln -sv "/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge" /usr/local/bin/smerge

Installing Sublime Text's command line tool 'subl' in terminal, permission denied?

I'm tryng to use Sublime Text from the terminal, for example by typing subl.
I'm following the steps from Sublime Text's website:
Setup
The first task is to make a symlink to subl. Assuming you've placed Sublime Text 2 in the Applications folder, and that you have a ~/bin directory in your path, you can run:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
I keep getting permission denied : ~/bin/subl: Permission Denied
I have been searching around for a similar problem but can't find one that's applicable. Can someone point me to the right direction?
I am assuming that you don't have the bin directory. You can do the following:
cd
mkdir bin
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
ln -s will create a alias of the subl file in your bin directory and you will be able to run the command.
If this still doesn't work you will have to edit your .bash_profile. You can do it by following commands: (NOTE: For this to work you need to have done the above steps already.)
Open your .bash_profile:
cd // this will get you back to home directory
vim .bash_profile // this will open your .bash_profile file
Edit .bash_profile: press I to get into "insert" mode and add following:
export PATH=$PATH:~/bin
Save and exit. Press Esc to get into command mode:
:wq // saves and close file
exit // exits terminal
Reopen the terminal:
subl --help
That should bring up the help for Sublime Text.
My personal preference for the path to the third-party application-specific symbolic links (e.g. subl, brew, github, mate, etc) is:
/usr/local/bin
Why not /usr/bin/?
/usr/bin is a "sacred" place. It is generally recommended to store static binaries that are maintained by package management systems. subl is not this case.
subl is not stable enough to be stored in /usr/bin with other basic BSD binaries (e.g. find, man, make, etc). You must modify/delete subl symbolic link manually if (a) the developers of Sublime Text Editor decide to change its app name in the future releases (as BBEdit Lite was changed to TextWrangler after version 6.1), or (b) you may simply wish to uninstall Sublime Text Editor.
Therefore, I suggest you execute the following line, assuming /usr/local/bin/ exists:
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Check whether "~/bin/" is included in the path.
A better options is to create the symlink in /usr/bin directory instead.
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl

Resources