Sublime Forum

Automatically update Sublime Text 3 on Linux

#1

I wrote a little python 3 script to automatically check for an updated version and install it for debian-based Linux systems, maybe this will be useful to someone.

You can set it on the dev or stable channel and retries automatically if sublimetext.com gives http 500 errors.
Needs to be run as root to run apt and dpkg.

I added sudo python3 updatesublime.py to my update script and works flawlessy. Any contribution or correction is welcome, just open a PR on github.

2 Likes

#2

any reason why you chose to not use the JSON API to get the latest version?

2 Likes

#3

Didn’t know about that. Just pushed an update, the script now fetches the latest version from the JSON API.

1 Like

#4

for debian based systems, including Ubuntu and Linux Mint, there is a ppa for sublime text 3:
https://launchpad.net/~webupd8team/+archive/ubuntu/sublime-text-3

You can add the ppa to your repositories and any updates will be applied through the normal apt based package control system for your distribution.

0 Likes

#5

I use the following to install the latest dev version of ST3.

LATESTNUMBER=$(wget -O - https://www.sublimetext.com/3dev | grep -o 'href="https://download.sublimetext.com/Sublime Text Build [0-9][0-9][0-9][0-9].dmg"' | grep -o -E '[0-9]+')

# wget --quiet https://download.sublimetext.com/sublime-text_build-3112_amd64.deb && sudo dpkg -i sublime-text_build-3112_amd64.deb
wget --quiet https://download.sublimetext.com/sublime-text_build-${LATESTNUMBER}_amd64.deb && sudo dpkg -i sublime-text_build-${LATESTNUMBER}_amd64.deb

cwd=$(pwd)

mkdir -p ~/.config/sublime-text-3/Installed\ Packages
cd ~/.config/sublime-text-3/Installed\ Packages/
wget --quiet https://packagecontrol.io/Package%20Control.sublime-package

mkdir -p ~/.config/sublime-text-3/Packages/User
cd ~/.config/sublime-text-3/Packages/User/
wget --quiet https://github.com/rudolfb/ubuntu-elixir-elm-install-shell-script/raw/master/sublime-text-3/Package%20Control.sublime-settings
wget --quiet https://github.com/rudolfb/ubuntu-elixir-elm-install-shell-script/raw/master/sublime-text-3/Terminal.sublime-settings

# Revert back to previous directory
cd $cwd

This will search for the latest ST3 dev version, download the file, install, then I ‘install’ the package control and fetch a list of the packages i use from my github account.

Modified my shell script to the following, taking into account the previous comments.

#!/bin/bash
arch=amd64
channel=dev

echo --------------------

if [ "$channel" = "dev" ]
then
	remoteversionurl="http://www.sublimetext.com/updates/3/dev/updatecheck?platform=linux&arch=x64"
else
	remoteversionurl="http://www.sublimetext.com/updates/3/stable/updatecheck?platform=linux&arch=x64"
fi

localversion=$(dpkg -s sublime-text | grep Version  | grep -o -E '[0-9]+')

json=$(wget --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 20 -O - ${remoteversionurl})
remoteversion=$(echo ${json} | grep -Po '"latest_version": \K[0-9]+')

# remoteversion=$(wget -O - https://www.sublimetext.com/3${channel} | grep -o 'href="https://download.sublimetext.com/Sublime Text Build [0-9][0-9][0-9][0-9].dmg"' | grep -o -E '[0-9]+')

remoteurl=https://download.sublimetext.com/sublime-text_build-${remoteversion}_${arch}.deb
filename=sublime-text_build-${remoteversion}_${arch}.deb

echo --------------------

echo version json=${json}

echo --------------------
echo ${cwd}
echo channel=${channel} 
echo localversion=${localversion}
echo remoteversion=${remoteversion}
echo remoteurl=${remoteurl}
echo remoteversionurl=${remoteversionurl}
echo filename=${filename}
echo --------------------

if [ -z "$remoteversion" ]
then
	echo 'remoteversion variable is undefined'
	exit 1
fi

if [[ "$localversion" != "$remoteversion" ]]
then
	echo Update Sublime Text 3 from ${localversion} to ${remoteversion} 
	wget --quiet ${remoteurl} && sudo dpkg -i ${filename}
	rm ${filename}
else
	echo Sublime Text 3 local version ${localversion} is up to date  
fi

echo --------------------

The only issues I have with this new script is sometimes the script returns ERROR 500: Internal Server

1 Like

#6

Updated my shell script to install/update Sublime Text 3 and posted the result to github:

The script determines the latest available version, then downloads and installs the tarball. Tested successfully on Fedora 25. There are a few parameters that allow on to choose between DEV and STABLE, specify a specific version number, and specify the installation folder.

Usage: {script} [ OPTIONS ] TARGET BUILD

  TARGET        Installation target. Default target is "/opt".
  BUILD         Build number, e.g. 3126. If not defined uses a Sublime Text 3 
                  web service to retrieve the latest stable or dev version number.

OPTIONS
  -h, --help    Displays this help message.
  -d, --dev     Install the dev version
  -s, --stable  Install the stable version (default)

The following will install the latest stable version of ST3:

cd sublime-text-3-install
chmod +x sublime-text-3.sh
./sublime-text-3.sh

This will install the latest dev version of ST3:

./sublime-text-3.sh -d

This will install a specific stable version of ST3 in a non-standard folder:

./sublime-text-3.sh -s /usr/local 3126

Uses the JSON API to determine the latest available version.

1 Like

#7

Good news- Linux repository support added today.

https://www.sublimetext.com/docs/3/linux_repositories.html

1 Like