Using snap Application Aliases

If you run snap and snapd <= 2.25 this is how you can set up aliases for snap applications in your snapcraft.yml:

      command: usr/bin/wrapper-psql
      aliases: [psql]
      plugs: [network]

Build and install your snap package. Then you need to enable all such aliases manually as the user you plan to run your application as. Normally, it is an unprivileged user.

Before you can enable an alias, though, you need to make sure you’re logged in:

$ sudo snap login
Email address: *****
Password of "*****": 
Login successful

Otherwise you won’t be able to create aliases as an unprivileged user (only as root via sudo.)

Enable your alias:

$ snap alias postgresql93.psql psql
 - postgresql93.psql as psql

Verify it was created:

$ snap aliases
Command Alias Notes
postgresql93.psql psql manual

Use the alias:

$ whereis psql
psql: /snap/bin/psql
$ psql --version
psql (PostgreSQL) 9.3.17

Remove your alias:

$ snap unalias psql
 - postgresql93.psql as psql

Aliases are unique:

$ snap alias postgresql94.psql psql
error: cannot perform the following tasks:
- Setup manual alias "psql" => "psql" for snap "postgresql94" (cannot enable alias "psql" for "postgresql94", already enabled for "postgresql93")

They can also be enabled automatically upon installation of a snap package when it is installed from a store.

Note, in snap version => 2.26 this behavior will change.

Read more about aliases and upcoming changes here.