How to automatically update Atom editor?

39,290

Solution 1

TL;DR If you do not want to use the PPA, you can use a script to download and automatically install via cron.


  1. Create a new file atom-auto-update

    sudo nano /usr/local/bin/atom-auto-update
    
  2. Add the following lines

    #!/bin/bash
    wget -q https://github.com/atom/atom/releases/latest -O /tmp/latest
    wget -q $(awk -F '[<>]' '/href=".*atom-amd64.deb/ {match($0,"href=\"(.*.deb)\"",a); print "https://github.com/" a[1]} ' /tmp/latest) -O /tmp/atom-amd64.deb
    dpkg -i /tmp/atom-amd64.deb
    
  3. Save the file and make it executable

    sudo chmod +x /usr/local/bin/atom-auto-update
    
  4. Test the script

    sudo atom-auto-update
    
  5. Create a cronjob for the script

    sudo crontab -e
    
  6. Add this line

    e.g.: at 10 am every week

    0 10 * * 1 /usr/local/bin/atom-auto-update
    

    e.g.: at 10 am every day

    0 10 * * * /usr/local/bin/atom-auto-update      
    

Explanation

  • wget -q https://github.com/atom/atom/releases/latest -O /tmp/latest

    Download the site with the latest version information

  • wget -q $(awk -F '[<>]' '/href=".*atom-amd64.deb/ {match($0,"href=\"(.*.deb)\"",a); print "https://github.com/" a[1]} ' /tmp/latest) -O /tmp/atom-amd64.deb

    1. … awk -F '[<>]' '/href=".*atom-amd64.deb/ {match($0,"href=\"(.*.deb)\"",a); print "https://github.com/" a[1]} ' /tmp/latest …

      Extract the download link

    2. wget -q $( … ) -O /tmp/atom-amd64.deb

      Download the DEB file

  • dpkg -i /tmp/atom-amd64.deb

    Install the DEB file

Solution 2

A.B's Answer is a nice solution! I added show progress bar option in the bash code to notify progress: 

#!/bin/bash
wget -q https://github.com/atom/atom/releases/latest -O /tmp/latest
wget --progress=bar -q 'https://github.com'$(cat /tmp/latest | grep -o -E 'href="([^"#]+)atom-amd64.deb"' | cut -d'"' -f2 | sort | uniq) -O /tmp/atom-amd64.deb -q --show-progress
dpkg -i /tmp/atom-amd64.deb

Solution 3

As the previous answer with minor modification, to let updating on start-up, here is the procedure

  1. Create file by running the command:

    sudo nano /usr/local/bin/atom-update  
    

then type the below script (use text-editor like "gedit" or "mousepad" instead of "nano" is more convenient) and then save it.

#!/bin/bash    
wget -q https://github.com/atom/atom/releases/latest -O /tmp/latest
MATCHEDROW=$(awk -F '[<>]' '/href=".*atom-amd64.deb/' /tmp/latest)
LATEST=$(echo $MATCHEDROW | grep -o -P '(?<=href=").*(?=" rel)')
VER_LATEST=$(echo $MATCHEDROW | rev | cut -d"/" -f 2 | rev | sed 's/v//g')
VER_INST=$(dpkg -l atom | tail -n1 | tr -s ' ' | cut -d" " -f 3)

if [ "$VER_LATEST" != "$VER_INST" ]; then
   wget --progress=bar -q "https://github.com/$LATEST" -O /tmp/atom-amd64.deb --show-progress
   dpkg -i /tmp/atom-amd64.deb
   echo "Atom has been update from $VER_LATEST to $VER_INST"
   logger -t atom-update "Atom has been update from $VER_INST to $VER_LATEST"
else
   echo "Atom version $VER_INST is the latest version, no update require"
   logger -t atom-update "Atom version $VER_INST is the latest version, no update require"
fi
  1. To make the file executable:

    sudo chmod +x /usr/local/bin/atom-update
    
  2. Now you could manually update Atom by typing the command:

    sudo atom-update
    
  3. Login to your root, and then add the below row to /etc/rc.local (sudo nano /etc/rc.local) just before exit 0 command:

    /usr/local/bin/atom-update  
    

This will let the atom update script execute every time you turn on your PC.

  1. To check that the script has run properly on start up, restart your PC and open the terminal then type:

    cat /var/log/syslog | grep 'atom.*'  
    

You will see the log message accordingly.

Solution 4

Well, another more elegant version with support of beta branch, if script launched with beta argument: $ update-atom beta

#!/bin/bash
DLPATH="https://atom.io/download/deb"
DLDEST="$HOME/Downloads/atom-amd64.deb"

if ! [ -z "$1" ] && [ $1=="beta" ];  then
  echo "Updating beta"
  DLPATH="$DLPATH?channel=beta"
  DLDEST="$HOME/Downloads/atom-amd64-beta.deb"
else
  echo "Updating stable"
fi

rm -f $DLDEST
wget -O $DLDEST $DLPATH 
sudo dpkg -i $DLDEST

Solution 5

Building on A.B's answer, I've added version checking to avoid unnecessary download/install:

#!/bin/bash

TMP_DIR=$(mktemp -d)

TMP_LATEST="${TMP_DIR}/latest"
TMP_FILE="${TMP_DIR}/atom-amd64.deb"

wget -q https://github.com/atom/atom/releases/latest -O ${TMP_LATEST}
LATEST=$(awk -F '[<>]' '/href=".*atom-amd64.deb/ {match($0,"href=\"(.*.deb)\"",a); print "https://github.com/" a[1]} ' ${TMP_LATEST})
VER_LATEST=$(echo $LATEST | rev | cut -d"/" -f 2 | rev | sed 's/v//g')

VER_INST=$(dpkg -l atom | tail -n1 | tr -s ' ' | cut -d" " -f 3)

if [ "$VER_LATEST" != "$VER_INST" ]; then
  wget -q $LATEST -O $TMP_FILE
  VER_DOWN=$(dpkg-deb -f $TMP_FILE Version)
  if [ "$VER_DOWN" != "$VER_INST" ]; then
    dpkg -i $TMP_FILE
  fi
fi

rm -rf "${TMP_DIR}"

Edit: I should clarify that this would replace the content of the /usr/local/bin/atom-auto-update script which A.B's answer mentions. The other steps of the answer are the same.

Share:
39,290

Related videos on Youtube

Igor V.
Author by

Igor V.

Updated on September 18, 2022

Comments

  • Igor V.
    Igor V. over 1 year

    Automatic update of Atom feature is not yet supported for Ubuntu. From their GitHub repository:

    Currently only a 64-bit version is available.

    Download atom-amd64.deb from the Atom releases page. Run sudo dpkg --install atom-amd64.deb on the downloaded package. Launch Atom using the installed atom command. The Linux version does not currently automatically update so you will need to repeat these steps to upgrade to future releases.

    I tried using Webupd8 PPA but it doesn't work for me.

    • A.B.
      A.B. almost 9 years
      What is the problem with the PPA?
    • Igor V.
      Igor V. almost 9 years
      @A.B. I think is ok now, didn't get the time to test it and I am not using atom for some time now, but back then PPA didn't updated my version.
    • A.B.
      A.B. almost 9 years
      I probably should not answer old questions. :\
    • Igor V.
      Igor V. almost 9 years
      Your answer is great and it would help me for similar problems. :)
  • Fabby
    Fabby almost 9 years
    An edit and an upvote! ;-)
  • karel
    karel over 7 years
    Suggestion for changing your GitHub page: under the Usage heading replace The package check for new version of Atom at launch with The package checks for a new version of Atom at launch Under the Why "geiger"? heading replace outadet Atom with outdated Atom
  • mac
    mac over 7 years
    @karel - Thank you, done. Some of the errors were due to this bug. :)
  • Rachid O
    Rachid O over 7 years
    awk: line 1: syntax error at or near , wget : URL manquante Utilisation : wget [OPTION]... [URL]...
  • becko
    becko over 7 years
    If I update this way, do I have to resintall the packages?
  • Dean Rather
    Dean Rather over 7 years
    This also gave me a syntax error where you try extract the URL from the HTML. They probably changed the HTML since then. This worked for me (not complete): cat /tmp/latest | grep '.deb' | grep 'href=' | cut -d '"' -f 2
  • SallyRothroat
    SallyRothroat over 7 years
    It's not working anymore. Can you update it please?
  • Felipe Elia
    Felipe Elia almost 7 years
    For those facing the awk syntax error, here is my third row: wget https://github.com$(cat /tmp/latest | grep -o -E 'href=".*atom-amd64.deb' | cut -d'"' -f2) -O /tmp/atom-amd64.deb
  • Ramon Suarez
    Ramon Suarez over 6 years
    Is there a difference in performance or usage between Atom installed via snap or apt? I don't really understand how to choose one or the other in general. Thanks.
  • Jorge Castro
    Jorge Castro over 6 years
    I've been using it like this for a long time with no issues, I prefer it to their debs because it autoupdates instead of reminding me to update all the time.
  • Pablo Bianchi
    Pablo Bianchi about 6 years
    I'm confuse if this really upgrade my Atom, I get Atom has been update from 1.23.3 to 1.19.7. If I download current latest from Atom.io and sudo dpkg -i atom-amd64.deb then I get `Unpacking atom (1.23.3) over (1.19.7).
  • scones
    scones about 4 years
    output in cronjobs is a bad thing. your administrator will get spam from that