Why isn't Sublime Text link created? - macos

I'm trying to get Sublime Text 2 to open from Terminal. I'm using the following:
MacBook-Pro:project2 myusername$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
ln: /Users/myusername/bin/subl: No such file or directory
I'm not sure what is wrong. I'm following all the examples out there. Am I missing something?
Here's the output of an echo $PATH (updated path):
/Users/myusername/bin:/Users/myusername/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
This is on OSX 10.11.1

You most probably do not have a bin folder in your home directory. Create one by using
mkdir ~/bin
This will create the bin folder in your /Users/yourusername/ directory. In terminal the ~ is short for your home.
You will also have to append this folder to your path, i.e. create (or edit if it exists) a .profile file in your home directory and give it this content:
export PATH=/Users/yourusername/bin:$PATH
You will have to open a new terminal for this change to take place.

Use one of these 2 commands:
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl ~/bin/subl
or
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

Related

How to Open a File in Sublime3 from the Command Line on Mac OSX

I was following some intructions online to set up a link so that I can open a file in sublime from my terminal.
I cd into /usr/local/bin I see brew and subl.
Then, I followed the instructions to set up the symbolic link.
In the terminal, I typed ln -s "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Then I saw File exists in the terminal
However, when I tried to subl index.html,
I saw this message command not found.
Please advise
Thank you so much for all the answers. I found out that it was an administrative restriction because I was using a work laptop. I resolved it by re-installing sublime text using homebrew. Now, it's working fine.
brew cask install sublime-text
Thanks again.
First up, check your own $PATH by running: echo $PATH. It should return something like this
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Make sure /usr/local/bin is in the path
Then run
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Note that the directory sublime text 3 is in is
"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
and not
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
Which is what you ran. Hope this helps.
It's not due to administrative restriction and you don't have to re-install sublime text.
As File exists suggests, the file has already exist, that's why your typing doesn't work.
Run rm /usr/local/bin/subl first to delete the exist file.
Then run ln -s "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl should solve your problem.
Take me for example,
my app is named Sublime Text 3 instead of Sublime Text.
I ran ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl as people suggest.
It didn't work due to the wrong path while the subl file created.
So I had to delete the existed file using rm /usr/local/bin/subl.
Then ran ln -s "/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl instead.
All things work now!!!
I am on El capitan and what worked for me was
running ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
This only works if you check how your extension is named under info
Also on the terminal you can't call sublime because you created it as subl instead so you have to write that in terminal
and then in terminal running subl . (to open a file )

Symlink to application in mac

I created a symlink to sublime text editor like this in my bin folder:
ln -s /Applications/Sublime\ Text\ 2.app/Contents/MacOS/Sublime\ Text\ 2 ~/bin/sublime
I exported the bin folder to the PATH in .bash_profile like this:
export PATH="$HOME/bin:$PATH"
When I try to open sublime by typing sublime in terminal i get:
xxxxx#xxxx-Air:~$ sublime
2015-08-06 08:05:16.238 sublime[2495:355442] Sparkle Error: the bundle being updated at {
} has no CFBundleIdentifier! This will cause preference read/write to not work properly.
On the other hand, when I try to type the full path like this it works fine:
xxxxx#xxxxx-Air:~$ /Applications/Sublime\ Text\ 2.app/Contents/MacOS/Sublime\ Text\ 2
Is there something wrong with my symlink?
To launch Sublime Text 2 from the Mac OS X Terminal, create a symlink to SharedSupport/bin/subl instead of MacOS/Sublime\ Text\ 2:
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl ~/bin/subl
Yeah. When you did the ln -s command, you didn't link all the way to the binary file for the app. So you got a wacky / unexpected response instead of launching that editor.
Try doing this instead:
ln -s /Applications/Sublime\ Text\ 2.app/Contents/MacOS/Sublime\ Text\ 2 ~/bin/sublime

Why do I get "subl: command not found"?

I am trying to access and manipulate the .gitignore file in Sublime via the terminal and I ran into this:
subl .gitignore
-bash: subl: command not found
Why can't it find it?
From the official documentation:
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

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

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

Resources