I followed below process for Groovy setup in Jenkins(using version 2.138.1) in the centos server
Manage Jenkins -> Manage Plugins -> Groovy plugin installed
Global Tool Configuration -> as attached jpg
Then added a Freestyle Project --> build --> Execute Groovy Script --> selected "groovy_2.5.2", then "Groovy command" and then script "println 'Its groovy!!'" --> svaed
Clicked "Build now"
Building in workspace /var/lib/jenkins/workspace/groovytest
to /var/lib/jenkins/tools/hudson.plugins.groovy.GroovyInstallation/groovy_2.5.2 on Jenkins
[groovytest] $ /var/lib/jenkins/tools/hudson.plugins.groovy.GroovyInstallation/groovy_2.5.2/bin/groovy /var/lib/jenkins/workspace/groovytest/hudson3857994244114045840.groovy
/var/lib/jenkins/tools/hudson.plugins.groovy.GroovyInstallation/groovy_2.5.2/bin/groovy: line 49: dirname: command not found
/var/lib/jenkins/tools/hudson.plugins.groovy.GroovyInstallation/groovy_2.5.2/bin/groovy: line 51: /startGroovy: No such file or directory
Build step 'Execute Groovy script' marked build as failure
When followed same process in my local it worked smoothly. Dont know why server is throwing error. I also checked /var/lib/jenkins/updates and found the file hudson.plugins.groovy.GroovyInstaller. I even uninstalled groovy plugin still same error.