How to install AppImage globally using bash?

203 Views Asked by At

I'm looking for a way to simplify the process of making an AppImage globally accessible on a Linux machine. How can I install an AppImage/put it in path without much additional work, so I can i.g. execute nvim everywhere in my linux

1

There are 1 best solutions below

1
On

Here's the script I came up with:

#!/bin/bash
if [ "$EUID" -ne 0 ]; then echo "Run as root." 1>&2; exit 1; fi
if [ "$#" -lt 1 ]; then echo "Usage: $0 <i/u> <AppImage_Name>" 1>&2; exit 1; fi
op="$1"; img="$2"
basename_no_ext=$(basename ${img%.*})

case "$op" in
  i|install)
    mv "$img" "/usr/local/bin/" && chmod +x "/usr/local/bin/$img" && ln -s "/usr/local/bin/$img" "/usr/local/bin/${img%.*}"
    if [ $? -eq 0 ]; then
      echo "Installed. Run $basename_no_ext."
    else
      echo "Installation failed." 1>&2
    fi
    ;;
  u|uninstall)
    rm -f "/usr/local/bin/$img" "/usr/local/bin/${img%.*}"
    if [ $? -eq 0 ]; then
      echo "Uninstalled."
    else
      echo "Uninstallation failed." 1>&2
    fi
    ;;
  *)
    echo "Invalid. Use 'i/u' or 'install/uninstall'." 1>&2
    exit 1
    ;;
esac

To install it: Copy above text to a local file named "install-app.sh", then execute in the same folder:

sudo ./install-app.sh i ./install-app.sh

Then, to use it, run:

sudo install-app i ./nvim.appimage

To uninstall, run:

sudo install-app u nvim

Feel free to improve or share this code.