Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dasgoll
Last active May 18, 2021 09:27
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dasgoll/675b2dc2f0916f8f0051 to your computer and use it in GitHub Desktop.
Save dasgoll/675b2dc2f0916f8f0051 to your computer and use it in GitHub Desktop.
### I assume you run the commands as root
gradle_version=2.6
wget -c http://services.gradle.org/distributions/gradle-${gradle_version}-all.zip
unzip gradle-${gradle_version}-all.zip -d /opt
ln -s /opt/gradle-${gradle_version} /opt/gradle
printf "export GRADLE_HOME=/opt/gradle\nexport PATH=\$PATH:\$GRADLE_HOME/bin\n" > /etc/profile.d/gradle.sh
source /etc/profile.d/gradle.sh
# check installation
gradle -v
@DineshShende
Copy link

I am getting erro bash: gradle: command not found for gradle -v

@jjmiv
Copy link

jjmiv commented Jun 9, 2016

make sure you run the . /etc/profile.d/gradle.sh script under the account you need to run gradle in.

@AndrewKralovec
Copy link

AndrewKralovec commented Sep 13, 2016

When i try to set the paths i get
sudo printf "export GRADLE_HOME=/opt/gradle\nexport PATH=$PATH:$GRADLE_HOME/bin\n" > /etc/profile.d/gradle.sh
-bash: /etc/profile.d/gradle.sh: Permission denied

Even with sudo

@shoaly
Copy link

shoaly commented Nov 2, 2016

I have the same problem, try this as follows:

  1. sudo vim /etc/profile.d/gradle.sh
  2. then, input manualy
  • export GRADLE_HOME=/opt/gradle
  • export PATH=$PATH:$GRADLE_HOME/bin
  1. :wq
  2. sh /etc/profile.d/gradle.sh
    it works for me

@MohammedShoaib
Copy link

I have the same problem, try this as follows:

  1. sudo vim /etc/profile.d/gradle.sh
  2. then, input manualy
  • export GRADLE_HOME=/opt/gradle
  • export PATH=$PATH:$GRADLE_HOME/bin
  1. :wq
  2. sh /etc/profile.d/gradle.sh
    it works for me

The point is to run this script, Not doing it manually

@vcarmen
Copy link

vcarmen commented Nov 13, 2018

In order to load the env variables, I needed to log out and log in again.
After that gradle --version works successfully

@arijitslg1
Copy link

As I am not much knowledgable about Linux so can anyone help me understand the purpose of using the command "export?. I have seen the same for installing ANT as well.

export GRADLE_HOME=/opt/gradle
export ANT_HOME=/opt/ant

I also checked in http://services.gradle.org/distributions/ where it shows the latest version of gradle is 5.6.2 so can I download this latest one along with the code that you have shared in this git?

@arijitslg1
Copy link

I followed these steps but it doesnt show work for me:

  1. wget -c http://services.gradle.org/distributions/gradle-5.6.2-src.zip-all.zip

  2. unzip gradle-5.6.2-src.zip -d /opt

  3. I verified that I these files under /opt/gradle then,
    [root@ip-xxx-xx-xx-xxx gradle]# ls -alh
    total 56K
    drwxr-xr-x 6 root root 228 Feb 1 1980 .
    drwxr-xr-x 5 root root 61 Sep 26 13:46 ..
    -rw-r--r-- 1 root root 13K Feb 1 1980 build.gradle.kts
    drwxr-xr-x 3 root root 101 Feb 1 1980 buildSrc
    drwxr-xr-x 3 root root 113 Feb 1 1980 config
    drwxr-xr-x 6 root root 225 Feb 1 1980 gradle
    -rw-r--r-- 1 root root 331 Feb 1 1980 gradle.properties
    -rwxr-xr-x 1 root root 5.9K Feb 1 1980 gradlew
    -rw-r--r-- 1 root root 2.9K Feb 1 1980 gradlew.bat
    -rw-r--r-- 1 root root 7.8K Feb 1 1980 released-versions.json
    -rw-r--r-- 1 root root 4.8K Feb 1 1980 settings.gradle.kts
    drwxr-xr-x 104 root root 4.0K Feb 1 1980 subprojects
    -rw-r--r-- 1 root root 6 Feb 1 1980 version.txt

  4. ln -s /opt/gradle-5.6.2 /opt/gradle

  5. sudo vi /etc/profile.d/gradle.sh
    export GRADLE_HOME=/opt/gradle
    export PATH=$PATH:$GRADLE_HOME/bin

  6. Then I tried in both commands but none of them worked.
    sh /etc/profile.d/gradle.sh
    source /etc/profile.d/gradle.sh

[root@ip-xxx-xx-xx-xxx ~]# gradle -v
-bash: gradle: command not found
[root@ip-xxx-xx-xx-xxx ~]# gradle --version
-bash: gradle: command not found

Any help will be appreciated.
OS: AWS Linux 2

@arijitslg1
Copy link

Its interesting that when I follow the same steps with a different version i.e. 5.6.2, it does not work.
http://services.gradle.org/distributions/gradle-5.6.2-src.zip-all.zip

However, if I try the same version as yours i.e. 2.6, it works fine.

Not sure what is so different during the configuration of these two versions. Anyone????

@raghuece455
Copy link

sudo mkdir /opt/gradle
wget -c https://services.gradle.org/distributions/gradle-4.2.1-bin.zip
sudo unzip -d /opt/gradle gradle-4.2.1-bin.zip
export PATH=$PATH:/opt/gradle/gradle-4.2.1/bin

gradle -v

Gradle 4.2.1

Build time: 2017-10-02 15:36:21 UTC
Revision: a88ebd6be7840c2e59ae4782eb0f27fbe3405ddf

Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_211 (Oracle Corporation 24.211-b02)
OS: Linux 4.14.62-65.117.amzn1.x86_64 amd64

Note: Java is prerequisite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment