Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Sublime Text 3 on Linux via POSIX shell script - http://simonewebdesign.it/install-sublime-text-3-on-linux/
#!/bin/sh
# Sublime Text 3 Install (last update: Monday 13 March 2017)
#
# No need to download this script, just run it on your terminal:
#
# curl -L git.io/sublimetext | sh
# Detect the architecture
if [[ "$(uname -m)" = "x86_64" ]]; then
ARCHITECTURE="x64"
else
ARCHITECTURE="x32"
fi
# Fetch the latest build version number (thanks daveol)
BUILD=$(echo $(curl http://www.sublimetext.com/3) | sed -rn "s#.*The latest build is ([0-9]+)..*#\1#p")
URL="https://download.sublimetext.com/sublime_text_3_build_{$BUILD}_{$ARCHITECTURE}.tar.bz2"
INSTALLATION_DIR="/opt/sublime_text"
# Download the tarball, unpack and install
curl -o $HOME/st3.tar.bz2 $URL
if tar -xf $HOME/st3.tar.bz2 --directory=$HOME; then
sudo mv $HOME/sublime_text_3 $INSTALLATION_DIR
sudo ln -s $INSTALLATION_DIR/sublime_text /usr/local/bin/subl
fi
rm $HOME/st3.tar.bz2
# Add to applications list and set icon
sed 's/Icon=sublime-text/Icon=\/opt\/sublime_text\/Icon\/128x128\/sublime-text.png/g' > $HOME/.local/share/applications/sublime_text.desktop
echo '
Sublime Text 3 installed successfully!
Run with: subl
'
@mariosant

This comment has been minimized.

Copy link

commented Feb 4, 2014

Hmmm... I would appreciate if it would show at the applications list of gnome 3.10. I tried copying the desktop entry into the /usr/share/applications but it didn't work.

@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Feb 22, 2014

Yeah, that would be really great. If anyone knows how to do that, please contribute.

EDIT: nevermind, I did it myself.

Anyway you are right; looks like just moving the desktop file into /usr/share/applications or ~/.local/share/applications doesn't work for some reason, so in the script I just added a new desktop entry manually.

@Soufien

This comment has been minimized.

Copy link

commented Mar 6, 2014

Thx a lot Simon ;) it was very useful !! ;)

@diek

This comment has been minimized.

Copy link

commented Mar 12, 2014

I am getting the following error:
./install_sublime_text3.sh: line 38: warning: here-document at line 24 delimited by end-of-file (wanted `EOF')

@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Mar 16, 2014

@diek: that's weird. Try to run it again with:

curl https://gist.githubusercontent.com/simonewebdesign/8507139/raw/e1e7f6a302d44902dc0805eaf85344f1c4e84425/install_sublime_text.sh | sh
@alexcreasy

This comment has been minimized.

Copy link

commented Apr 9, 2014

Works like a charm, thanks!

@heichblatt

This comment has been minimized.

Copy link

commented Apr 26, 2014

Just wanted to mention a script I built based on this.

@whitel

This comment has been minimized.

Copy link

commented Jul 25, 2014

@simonewebdesign and @qboss, you need to restart gnome to pick up new desktop files. For example, hit Alt-F2, type "r" (without the quotes) and click enter.

@dee1337

This comment has been minimized.

Copy link

commented Jul 27, 2014

my vm with fedora 19 32bit ran into an error using this version
bash: /usr/bin/subl: cannot execute binary file
...so i added 32bit support:
https://gist.github.com/dee1337/80b24a66c5e6a0cd97d9

@allanlewis

This comment has been minimized.

Copy link

commented Aug 29, 2014

Sublime Text just released build 3065...

@ghost

This comment has been minimized.

Copy link

commented Aug 29, 2014

Love it! Works like a charm! Thank you!

@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Sep 1, 2014

FYI: I'm working on a new version of the script that will install the latest build (3065) and will detect the correct OS architecture (i386 or x64).

@bhalothia

This comment has been minimized.

Copy link

commented Sep 17, 2014

Thanks a ton! :)

@4ndrej

This comment has been minimized.

Copy link

commented Oct 22, 2014

there is desktop file already (at least in latest sublime text 3 v3.065), so the extraction should go to sublime_text (not the sublime_text_3) and the last part of installer could be changed to
ln -s /opt/sublime_text/sublime_text.desktop /usr/share/applications/sublime_text.desktop

@dimitrismistriotis

This comment has been minimized.

Copy link

commented Dec 12, 2014

Maybe because of the curl command we should guard against some exited OS/X users, maybe on line 11:

if [ `uname` = 'Darwin' ]; then echo 'Not for OS/X, use brew cask'; exit -1; fi
@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Dec 16, 2014

Thanks for your input Dimitri, however I believe there's no need to alert OS X users as they already have a .dmg file at their disposal from the official site, so they probably won't search for an installation script anyway

@pachecovit

This comment has been minimized.

Copy link

commented Jan 8, 2015

How add a 'official' icon on shortcut? I have OCD :'(

@dimitrismistriotis

This comment has been minimized.

Copy link

commented Jan 8, 2015

For elementaryOS
After installing, based on http://elementaryos.org/answers/create-shortcut-of-terminal-commands-in-dock-panel:

subl ~/.local/share/applications/sublime.desktop
[Desktop Entry]
Type=Application
Name=Sublime Text
GenericName=Sublime Text
Exec=subl
Terminal=false
Icon=/opt/sublime_text/Icon/128x128/sublime-text.png

Maybe in another version do a check and append it on bottom?

@ahockersten

This comment has been minimized.

Copy link

commented Mar 20, 2015

I started fixing som annoyances I had with this script, and basically ended up rewriting the whole thing, see:
https://gist.github.com/ahockersten/9781d1233e2bb125b458

Changes:

  • Now has an uninstaller (since I have changed a bunch of paths, this won't work if you previously installed with another version of the script)
  • Icons are installed correctly
  • No sudo inside script, it should be run as root or using sudo instead
  • Better (but not perfect) error handling
  • Better install directories (uses /usr/local for the subl script)
  • Installing Package Control is now optional (use -p)
  • Previously, if you ran "subl" from the command line and used the desktop shortcut, you would get two icons in Gnome's taskbar. I've fixed so that this no longer happens.
@SystemDisc

This comment has been minimized.

Copy link

commented Mar 30, 2015

For anyone who wants an RPM for Sublime Text 3 with everything included: https://mega.co.nz/#!eAAkARQR!dvMZGO49xxxPt_tuRrhYip7IIfhp9dhQzhEmT5i9S14

[systemdisc@localhost ~]$ rpm -qp sublime-3-1.x86_64.rpm -l
/opt/sublime_text/Icon/128x128/sublime-text.png
/opt/sublime_text/Icon/16x16/sublime-text.png
/opt/sublime_text/Icon/256x256/sublime-text.png
/opt/sublime_text/Icon/32x32/sublime-text.png
/opt/sublime_text/Icon/48x48/sublime-text.png
/opt/sublime_text/Packages/ASP.sublime-package
/opt/sublime_text/Packages/ActionScript.sublime-package
/opt/sublime_text/Packages/AppleScript.sublime-package
/opt/sublime_text/Packages/Batch File.sublime-package
/opt/sublime_text/Packages/C#.sublime-package
/opt/sublime_text/Packages/C++.sublime-package
/opt/sublime_text/Packages/CSS.sublime-package
/opt/sublime_text/Packages/Clojure.sublime-package
/opt/sublime_text/Packages/Color Scheme - Default.sublime-package
/opt/sublime_text/Packages/D.sublime-package
/opt/sublime_text/Packages/Default.sublime-package
/opt/sublime_text/Packages/Diff.sublime-package
/opt/sublime_text/Packages/Erlang.sublime-package
/opt/sublime_text/Packages/Go.sublime-package
/opt/sublime_text/Packages/Graphviz.sublime-package
/opt/sublime_text/Packages/Groovy.sublime-package
/opt/sublime_text/Packages/HTML.sublime-package
/opt/sublime_text/Packages/Haskell.sublime-package
/opt/sublime_text/Packages/Java.sublime-package
/opt/sublime_text/Packages/JavaScript.sublime-package
/opt/sublime_text/Packages/LaTeX.sublime-package
/opt/sublime_text/Packages/Language - English.sublime-package
/opt/sublime_text/Packages/Lisp.sublime-package
/opt/sublime_text/Packages/Lua.sublime-package
/opt/sublime_text/Packages/Makefile.sublime-package
/opt/sublime_text/Packages/Markdown.sublime-package
/opt/sublime_text/Packages/Matlab.sublime-package
/opt/sublime_text/Packages/OCaml.sublime-package
/opt/sublime_text/Packages/Objective-C.sublime-package
/opt/sublime_text/Packages/PHP.sublime-package
/opt/sublime_text/Packages/Pascal.sublime-package
/opt/sublime_text/Packages/Perl.sublime-package
/opt/sublime_text/Packages/Python.sublime-package
/opt/sublime_text/Packages/R.sublime-package
/opt/sublime_text/Packages/Rails.sublime-package
/opt/sublime_text/Packages/Regular Expressions.sublime-package
/opt/sublime_text/Packages/RestructuredText.sublime-package
/opt/sublime_text/Packages/Ruby.sublime-package
/opt/sublime_text/Packages/SQL.sublime-package
/opt/sublime_text/Packages/Scala.sublime-package
/opt/sublime_text/Packages/ShellScript.sublime-package
/opt/sublime_text/Packages/TCL.sublime-package
/opt/sublime_text/Packages/Text.sublime-package
/opt/sublime_text/Packages/Textile.sublime-package
/opt/sublime_text/Packages/Theme - Default.sublime-package
/opt/sublime_text/Packages/Vintage.sublime-package
/opt/sublime_text/Packages/XML.sublime-package
/opt/sublime_text/Packages/YAML.sublime-package
/opt/sublime_text/changelog.txt
/opt/sublime_text/crash_reporter
/opt/sublime_text/plugin_host
/opt/sublime_text/python3.3.zip
/opt/sublime_text/sublime.py
/opt/sublime_text/sublime_plugin.py
/opt/sublime_text/sublime_text
/usr/local/bin/sublime_text
/usr/share/applications/sublime_text.desktop
@taotie12010

This comment has been minimized.

Copy link

commented Apr 5, 2015

thx,it is very helpful.

@jzgdev

This comment has been minimized.

Copy link

commented Jun 5, 2015

Thanks for this, worked perfectly on Fedora 22

@dud3

This comment has been minimized.

Copy link

commented Jun 20, 2015

This just doesn't work on Fedora 22: /usr/local/bin/subl: line 2: [: ==: unary operator expected

@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Jun 23, 2015

@dud3: some other people reported the same problem many times, but I haven't been able to reproduce it since then. Could you provide some more details (e.g. OS architecture, shell)?

Have you tried running the script again?

@FlorianMiesenberger

This comment has been minimized.

Copy link

commented Jul 2, 2015

@dud3: I have got the same error on Fedora 22 ... 👎

@kane-thornwyrd

This comment has been minimized.

Copy link

commented Jul 7, 2015

@dud3 and the others, just add a check for the args count...

#!/bin/sh
if [ $# -gt 0 ] && [ ${1} == "--help" ]; then
/usr/local/sublime-text_3/sublime_text --help
else
/usr/local/sublime-text_3/sublime_text $@ > /dev/null 2>&1 &
fi
@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Jul 12, 2015

@ALL: Works on Fedora 22 Workstation (64-Bit).
I haven't tested other platforms though, so please let me know if you have any issues at all.

@VarunBarad

This comment has been minimized.

Copy link

commented Sep 3, 2015

@simon
Thanks, it worked like a charm on Fedora 21 Workstation (64-Bit).

@williamcanin

This comment has been minimized.

Copy link

commented Sep 11, 2015

Very good, more if the person wants to cancel the process when enter the password for sudo, it will have to press Ctrl + C three times per exist three dependent on the sudo command (one example).
To circumvent this, and cancel all "sudo" when only is pressed once the Ctrl + C, insert the code below before all commands using "sudo":

#Function that cancels all "sudo" with Ctrl + C
trap ctrl_c INT
sudo -k # Reset sudo
function ctrl_c() {
echo "Aborted."
exit 0
}
echo
echo "For cancel, press Ctrl+C"

@ea2305

This comment has been minimized.

Copy link

commented Sep 27, 2015

Thank you, I really need this :)

@iferrant

This comment has been minimized.

Copy link

commented Oct 23, 2015

Thanks ! Works perfect in Fedora 22!

@agbenu

This comment has been minimized.

Copy link

commented Nov 11, 2015

In my case I had to extend it by an extra sublime_text before it could work. So finally I ended up with something like

if [ $# -gt 0 ] && [ ${1} == "--help" ]; then
/usr/local/sublime-text-3/sublime_text_3/sublime_text --help
else
/usr/local/sublime-text-3/sublime_text_3/sublime_text $@ > /dev/null 2>&1 &
fi

Hope it helps someone out.

@davidmason

This comment has been minimized.

Copy link

commented Nov 24, 2015

Install appeared to work on F23, but I later realized I can't install any packages. I had copied my config from my previous install so I didn't notice at first as my existing packages were still there. I removed my old config to have it start from scratch in case that was the cause, but the following still happens:

In the sublime console straight after startup (with no files open):

DPI scale: 1
startup, version: 3083 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
working dir: /home/damason
packages path: /home/damason/.config/sublime-text-3/Packages
state path: /home/damason/.config/sublime-text-3/Local
zip path: /opt/sublime_text/Packages
zip path: /home/damason/.config/sublime-text-3/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.074854
startup time: 0.144206
first paint time: 0.148921
reloading plugin Default.block
<snip>
reloading plugin Default.trim_trailing_white_space
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin Package Control.1_reloader
reloading plugin Package Control.2_bootstrap
reloading plugin Package Control.Package Control
plugins loaded
Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 158, in on_api_ready
    m.plugin_loaded()
  File "2_bootstrap in /opt/sublime_text/Packages/Package Control.sublime-package", line 103, in plugin_loaded
  File "package_control.loader in /opt/sublime_text/Packages/Package Control.sublime-package", line 193, in add
  File "./zipfile.py", line 919, in __init__
FileNotFoundError: [Errno 2] No such file or directory: '/opt/sublime_text/Installed Packages/0_package_control_loader.sublime-package'
Package Control: Not running package cleanup since bootstrapping is not yet complete

Then when I run Package Control: Install Package and select a package to install, it adds:

Traceback (most recent call last):
  File "package_control.package_installer in /opt/sublime_text/Packages/Package Control.sublime-package", line 159, in on_done
  File "package_control.package_disabler in /opt/sublime_text/Packages/Package Control.sublime-package", line 74, in disable_packages
ImportError: No module named 'package_control'

Any idea why this would happen or how I can fix it?

@f0t0n

This comment has been minimized.

Copy link

commented Jan 17, 2016

Same here. Choose and select a package to install and nothing happens. The console output is listed below.

Traceback (most recent call last):
  File "package_control.package_installer in /home/f0t0n/.config/sublime-text-3/Installed Packages/Package Control.sublime-package", line 159, in on_done
  File "package_control.package_disabler in /home/f0t0n/.config/sublime-text-3/Installed Packages/Package Control.sublime-package", line 74, in disable_packages
ImportError: No module named 'package_control'
@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Jan 26, 2016

I'm not sure why that is happening or how I can fix it. I don't know if it's related to the install script. I'll investigate.

@cyberdemon8

This comment has been minimized.

Copy link

commented Feb 9, 2016

The url for download is changed with latest 3103 version, please change row 22 from:
URL="http://c758482.r82.cf2.rackcdn.com/sublime_text_3_build_{$BUILD}_{$ARCHITECTURE}.tar.bz2"
to
URL="https://download.sublimetext.com/sublime_text_3_build_{$BUILD}_{$ARCHITECTURE}.tar.bz2"

@binaryreverse

This comment has been minimized.

Copy link

commented Feb 11, 2016

Thanks for the last comment on the changed URL. This worked without problems.

@levilliard

This comment has been minimized.

Copy link

commented Feb 21, 2016

Thx a lot ! Works perfect on Fedora 23

@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Mar 3, 2016

The issue regarding the package manager has been fixed. If anyone has encountered any other issues at all just let me know.

@djx2unv

This comment has been minimized.

Copy link

commented Mar 5, 2016

Worked out, Fedora 23. Thanks a lot, bro!! Best regards!

@Koisell

This comment has been minimized.

Copy link

commented Apr 21, 2016

I have the 3083 built and I want to update it without losing any package I installed through Package Control. How can I do?

@mlaine288

This comment has been minimized.

Copy link

commented May 4, 2016

I had to update https://sublime.wbond.net/ to https://packagecontrol.io
Ortherwise curl launch an SSL error

also change /bin/subl to /usr/local/bin/subl (otherwise I get an error message with the subl command... RHEL specific I guess)

Lastly create "Installed Package" sub folder before moving package control file there.

(RHEL 6)

@mlaine288

This comment has been minimized.

Copy link

commented May 4, 2016

@Koiseli:
I think your packages are installed in $HOME/.conf/Installed \Packages or Packages
If not, you should move those from the /opt/sublime-text/Installed \Packages there and put a symbolic link in place

@David-Else

This comment has been minimized.

Copy link

commented Jul 5, 2016

hi, is this confirmed working in fedora24? thanks!

@hebertjulio

This comment has been minimized.

Copy link

commented Sep 22, 2016

Yes! I am using Fedora 24 and it work fine for me. 👍 Great job!

@rahulchhangani

This comment has been minimized.

Copy link

commented Sep 24, 2016

Getting Error
/usr/local/bin/subl: line 2: [: ==: unary operator expected

@neok-m4700

This comment has been minimized.

Copy link

commented Nov 5, 2016

Very convenient script, thanks !

I just had to change one line to make it work on FEDORA 24:

$ curl -LO git.io/sublimetext
$ sed -i '\,sudo mv $HOME/Package,i sudo mkdir -p "$INSTALLATION_DIR/Installed Packages"' sublimetext
$ sh sublimetext
@praneethng

This comment has been minimized.

Copy link

commented Feb 7, 2017

HI neok-m4700 can you give me the script you have used for fedora 24?
I was using sublime-text2 on fedora 22 after upgrading to fedora 24 i am not able to open sublimet-text2

@shanginn

This comment has been minimized.

Copy link

commented Feb 21, 2017

@praneethng here you go. I made 2 changes at lines #35 and #36
https://gist.github.com/shanginn/046eb3dfdd419a9aae3e2c078c7569a3
But I'm not really sure does it work or not.

@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented Mar 13, 2017

I've updated the script to no longer install Package Control, as it can now be installed very easily by pressing Ctrl+Shift+P and typing "package control".

@AdmiralAsshat

This comment has been minimized.

Copy link

commented May 28, 2017

Sublime Text appears to have an official repo for installing on Fedora now. Does this still need to exist? It has served me well, but at this point I just want migration/removal instructions so that I can safely switch to the official repo.

@simonewebdesign

This comment has been minimized.

Copy link
Owner Author

commented May 31, 2017

Nice, finally, thanks for pointing that out.

For the migration, unless you have fancy stuff, all you need to do is save your user configuration somewhere (e.g. one convention is to have a dotfiles repository, but you might as well just make a gist or keep it somewhere else), also keep note of your plugins and themes. When you're ready just do rm -rf $(which subl).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.