diff --git a/src/port/path.c b/src/port/path.c
index 7bf7cbc..33cb790 100644
--- a/src/port/path.c
+++ b/src/port/path.c
@@ -807,15 +807,24 @@ bool
 get_home_path(char *ret_path)
 {
 #ifndef WIN32
-	char		pwdbuf[BUFSIZ];
-	struct passwd pwdstr;
-	struct passwd *pwd = NULL;
-
-	(void) pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd);
-	if (pwd == NULL)
-		return false;
-	strlcpy(ret_path, pwd->pw_dir, MAXPGPATH);
-	return true;
+	char		*envhome = getenv("HOME");
+	if (envhome != NULL && strlen(envhome) > 0)
+	{
+		strlcpy(ret_path, envhome, MAXPGPATH);
+		return true;
+	}
+	else
+	{
+		char		pwdbuf[BUFSIZ];
+		struct passwd pwdstr;
+		struct passwd *pwd = NULL;
+
+		(void) pqGetpwuid(geteuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd);
+		if (pwd == NULL)
+			return false;
+		strlcpy(ret_path, pwd->pw_dir, MAXPGPATH);
+		return true;
+	}
 #else
 	char	   *tmppath;
 
