By default, sudo on the Linux systems executes commands into a minimal environment. So, if you for example has some non-standard directories (such as /opt/groovy/bin)
added to your PATH, a command running via sudo won't see any executable in these directories.
Normally, this strict sudo behavior can be changed by removing env_reset (or changing env_keep) variables in /etc/sudoers.
But what can you do in case when you have only restricted sudo without write access to this file?
The following command passes a current value of PATH under a command run with sudo privileges:
sudo bash -c "export $PATH; which groovy"