How to use default commands from those apps which are installed using SNAP without having to use "snap run" infront of original command?

If it is because where is there is NO way to run snap app, then I am all ears.
After a recent discussion in reddit, I found out that in order to launch scrcpy I have to put snap run in front of the real command.

Apparently it’s a new way users can waste time typing more things which you didn’t have to type before if I remember correctly. I wish I could launch any app by its default command. Why snap devs did this? The more I learn to snap the more its getting my nerve.

Why things are not plain and simple?
Why it’s not straight forward?
Why not let the user run the app by its default command? Why there have to be extra words in front of it?

Are you familiar with the concept of the PATH variable? On Ubuntu systems, /snap/bin:/var/lib/snapd/snap/bin should be part of it by default. So it’s rather straightforward.

There is something wrong with your installation beacuse I can launch all snaps with normal commands.

I just checked scrcpy and it works without snap run.

$ scrcpy
ERROR: ld.so: object 'libgtk3-nocsd.so.0' from LD_PRELOAD cannot be preloaded (failed to map segment from shared object): ignored.
INFO: scrcpy 1.14 <https://github.com/Genymobile/scrcpy>
* daemon not running; starting now at tcp:5037
* daemon started successfully
adb: error: failed to get feature set: no devices/emulators found
ERROR: "adb push" returned with value 1

Do you have a file called apps-bin-path.sh in /etc/profile.d folder. That is the one that provides PATH variable for snaps.

See the 4.2 section of that article.

Also that file is provided by snapd package.

pranav@exam ~ [1]> cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "${PS1-}" ]; then
  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
pranav@exam ~> 

I use a Fish shell. Even if I switched to a bash shell, it’s the same thing. I CANNOT use just scrcpy command. All I did, was install scrcpy using Snap. I DIDN’T modify anything I don’t know.

should be part of it by default.

Well, I use Ubuntu 20.04.
I came from a stable release upgrade in Ubuntu 19.10.

It’s not straight forward in my case.

You’ve made a conscious choice to use your own setup. You can trivially adjust your setup to do what you need to do, but choose not to do that. The trivial adjustments are in no way arcane; they are simple modifications of the $PATH variable which have been common to unix-like systems for decades. The distribution maintainers cannot second-guess your own choices.

The output of systemctl --user show-environment |grep PATH should confirm that /snap/bin is in the PATH. However, in between the user sessiosn manager and your shell, PATH can get changed many times. Your shell is free to do anything and override PATH with some other value. The most common bash setup seems to work for everyone. Similarly, zsh users seem to be happy (unless they are on Debian or Ubuntu, because the package maintainer chose to not load sh profiles).

However, I have 0 idea about fish, AFAIK nobody on the team is a user of fish shell. I suggest you try the docs on the fish shell profile setup. Maybe it’s a bug in the stock package setup or something in your local setup.
FWIW, I’ve installed fish on Arch, and noticed no problems with the vanilla setup. All snap commands are available and $PATH looks correct, what further suggests it’s something in your setup or the Ubuntu package:

maciek@galeon ~> echo $PATH
/home/maciek/.cargo/bin /usr/local/bin /usr/local/sbin /usr/bin /var/lib/flatpak/exports/bin /usr/lib/jvm/default/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl /var/lib/snapd/snap/bin /home/maciek/bin /home/maciek/.local/bin

maciek@galeon ~> systemctl --user show-environment |grep -E '^PATH='
PATH=/home/maciek/.cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin

maciek@galeon ~> which ohmygiraffe 
/var/lib/snapd/snap/bin/ohmygiraffe

I just confirmed this by changing my shell to fish and rebooting.

It’s weird. I wonder if there’s a pattern that affects all the non-bash shells?

Tried changing to fish shell as my default shell via chsh. The snap is no longer included in the $PATH. It’s still listed in systemctl --user show-environment. So a default setup ignores that and sets its own PATH?

pranav@exam ~> echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
pranav@exam ~> systemctl --user show-environment |grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

@mborzecki

@Wimpress uses fish and can probably advise whether it works by default. But surely the issue here is that the original post was unnecessarily confrontational and can be remedied by the original poster following their shell’s documentation for adding the snap directory to their path?

Like I said before, even if I switch to bash, the problem remains the same.
pranav@exam ~> bash
pranav@exam:~$ scrcpy
Command ‘scrcpy’ is available in ‘/snap/bin/scrcpy’
The command could not be located because ‘/snap/bin’ is not included in the PATH environment variable.
scrcpy: command not found
pranav@exam:~$
@mcphail

Yes, because you need to modify your path. This is something which has affected your setup possibly related to your choice to switch shell in the first place. If it isn’t in your path, your shell isn’t going to see it. If you had been using bash and an unmodified environment it would work by default. This isn’t a snap problem and it isn’t a push to “advertise” snaps. The developers have given you an additional convenience function you can use if you don’t want to modify your path.

Switching shell is a recent activity. Like 10 days before.
I have install Scrcpy like months ago (but I don’t know “when” exactly for sure).

I don’t think switching shell will modify the path automatically.

@mcphail

Whatever has modified it, the solution is the same. Unless you have the path in your $PATH the shell will not see it. A default Ubuntu user will have the path in their $PATH already.

You may wish to reproduce this on a fresh install and file a bug if you think this is an issue.

Well I tried adding environment path using the article’s 4.2 section u mentioned but it didn’t last long:

> export PATH=$PATH:/snap/bin:/var/lib/snapd/snap/bin

After I exit the terminal all modifications gone in the wind.
@mcphail

I don’t use fish, but the documentation suggests you can run set -U fish_user_paths /snap/bin $fish_user_paths to set this permanently for your fish shells.

Edit: Fixed filename ~.profile/bashrc to ~/.profile, which is what I meant to write :slight_smile:

You should add that line to your ~/.profile or ~/.bashrc (do note that the latter is bash specific), the export command entered in the shell wont do nothing for future shell sessions. Also if you have to use snap run scrcpy then you might want to create a shell alias; this is shell specific, so for example for bash you would want to add this line in the ~/.bashrc file: alias scrcpy=‘snap run scrcpy’ …but really according to other posts, if snap is installed correctly and relevant directories propely included in system wide default PATH, then it should work like this. I have no idea is this is true for all the cases - makes me wonder why this didn’t seem to work for launching WickrMe, but I don’t know if all snap packages include a “launcher” that doesn’t need “snap run” in front of it. All that I’ve read before about launching snap applications have only mentioned using “snap run [appname]” so I don’t know. I was looking for something else, came to this post and just decided to offer whatever I can, except I can’t offer that much expertise with snap.

1 Like

AFAIK, all Snaps that provide commands work without snap run, as long as you have your PATH var set correctly - and this, as explained, dependes on your shell and environment setup. Vanilla Ubuntu will have all set, but if you start customizing, than it might be necessary some tinkering. Fortunatelly, setting PATH is usually trivial (or not very complicated) on most shells/setups.