Search code examples
ubuntuamazon-web-servicesamazon-ec2sudo

how to sudo jps on aws ec2 ubuntu


when I try $ sudo jps there is only error messages :

sudo: jps: command not found

when I not use sudo command, jps works well :

7762 Jps

===========

p.s.
my solution is sudo -E $JAVA_HOME/bin/jps but that is quite uncomfortable


Solution

  • Because sudo modifies PATH and the command jps is not found in the modified (root's) path. To preserve path:

    sudo env "PATH=$PATH" jps
    

    or

    alias sudo='sudo env PATH=$PATH'