Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
# Sublime Text 3 install script
# Reset in case getopts has been used previously in the shell.
OPTIND=1
# Default installation directory
# Note: this is hardcoded in the .desktop file provided by the ST3 tarball, so
# changing it will *not* work without manually editing that file
INSTALLATION_DIR="/opt/sublime_text"
PREFIX="/usr/local"
# Unfortunately it seems that Gnome doesn't look for icons in /usr/local,
# so icons have to be installed directly into /usr
ICON_PREFIX="/usr"
# Fetch latest build number from sublimetext.com
BUILD="$(echo $(curl http://www.sublimetext.com/3) | sed -rn "s#.*The latest build is ([0-9]+)..*#\1#p")"
# Detect the architecture
if [ "$(uname -m)" = "x86_64" ]; then
ARCHITECTURE="x64"
else
ARCHITECTURE="x32"
fi
URL="http://download.sublimetext.com/sublime_text_3_build_${BUILD}_${ARCHITECTURE}.tar.bz2"
function show_help {
echo "Helper script for installing Sublime Text 3."
echo "Run without options to download and install."
echo "Options:"
echo "-h Display this help message."
echo "-u Remove ST3 that was previously installed by this script."
echo "-p Also install Package Control."
}
function check_root {
if (( $EUID != 0 )); then
echo "Please run this script as root or use sudo."
exit 1
fi
}
function uninstall {
rm -rf $INSTALLATION_DIR
rm -f $PREFIX/bin/subl
rm -f $PREFIX/share/applications/sublime_text.desktop
rm -f $ICON_PREFIX/share/icons/hicolor/16x16/apps/sublime-text.png
rm -f $ICON_PREFIX/share/icons/hicolor/32x32/apps/sublime-text.png
rm -f $ICON_PREFIX/share/icons/hicolor/48x48/apps/sublime-text.png
rm -f $ICON_PREFIX/share/icons/hicolor/128x128/apps/sublime-text.png
rm -f $ICON_PREFIX/share/icons/hicolor/256x256/apps/sublime-text.png
gtk-update-icon-cache $ICON_PREFIX/share/icons/hicolor/
}
while getopts "h?up:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
u)
check_root
uninstall
exit 0
;;
p)
INSTALL_PACKAGE_CONTROL=1
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
check_root
# Download the tarball, unpack and install
curl -o /tmp/st3.tar.bz2 $URL
if tar -xf /tmp/st3.tar.bz2 --directory=/tmp; then
# Uninstall current installation, if it exists
uninstall
mv /tmp/sublime_text_3 $INSTALLATION_DIR
echo "#!/bin/sh" > /tmp/subl
echo "exec $INSTALLATION_DIR/sublime_text \"\$@\"" >> /tmp/subl
chmod +x /tmp/subl
mv /tmp/subl $PREFIX/bin
else
rm /tmp/st3.tar.bz2
exit 1
fi
rm /tmp/st3.tar.bz2
# optionally install package control
if [ -n "$INSTALL_PACKAGE_CONTROL" ]; then
curl -o $HOME/Package\ Control.sublime-package https://sublime.wbond.net/Package%20Control.sublime-package
mv $HOME/Package\ Control.sublime-package "$INSTALLATION_DIR/Packages/"
fi
# Add to applications list
ln -s $INSTALLATION_DIR/sublime_text.desktop $PREFIX/share/applications/sublime_text.desktop
# Add icons
ln -s $INSTALLATION_DIR/Icon/16x16/sublime-text.png $ICON_PREFIX/share/icons/hicolor/16x16/apps/sublime-text.png
ln -s $INSTALLATION_DIR/Icon/32x32/sublime-text.png $ICON_PREFIX/share/icons/hicolor/32x32/apps/sublime-text.png
ln -s $INSTALLATION_DIR/Icon/48x48/sublime-text.png $ICON_PREFIX/share/icons/hicolor/48x48/apps/sublime-text.png
ln -s $INSTALLATION_DIR/Icon/128x128/sublime-text.png $ICON_PREFIX/share/icons/hicolor/128x128/apps/sublime-text.png
ln -s $INSTALLATION_DIR/Icon/256x256/sublime-text.png $ICON_PREFIX/share/icons/hicolor/256x256/apps/sublime-text.png
gtk-update-icon-cache $ICON_PREFIX/share/icons/hicolor/
echo ""
echo "Sublime Text 3 installed successfully!"
echo "Run with: subl"
@binaryreverse

This comment has been minimized.

Copy link

binaryreverse commented Mar 24, 2015

Works great on Fedora 21 (64Bit). Thanks for the effort.

@daveol

This comment has been minimized.

Copy link

daveol commented Mar 27, 2015

use this

BUILD=$(echo $(curl http://www.sublimetext.com/3) | sed -rn "s#.*The latest build is ([0-9]+)..*#\1#p")

for getting the most recent build number rather than hard coding it

@SystemDisc

This comment has been minimized.

Copy link

SystemDisc 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
@ahockersten

This comment has been minimized.

Copy link
Owner Author

ahockersten commented Apr 21, 2015

@daveol: very nice! I have included the automatic build number fetching. Thank you!

@Ikerlb

This comment has been minimized.

Copy link

Ikerlb commented Jun 4, 2015

Works perfect. Thanks!

@pachecovit

This comment has been minimized.

Copy link

pachecovit commented Jun 23, 2015

Wohoooo! Works fine on Fedora 22, thanks!

@paladini

This comment has been minimized.

Copy link

paladini commented Dec 10, 2015

Works like a charm on Fedora 22, nice script!! :)

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.