diff --git a/src/nano.c b/src/nano.c
index 7a8caf86b8fd534163c8a45c81cf1b4019d75f85..64e523a8fc6f26ee171f2c5c03ab93abeeded871 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1980,6 +1980,11 @@ int main(int argc, char **argv)
 		{NULL, 0, NULL, 0}
 	};
 
+#ifdef __linux__
+	/* Check whether we're running on a Linux console. */
+	console = (getenv("DISPLAY") == NULL);
+#endif
+
 	/* Back up the terminal settings so that they can be restored. */
 	tcgetattr(0, &oldterm);
 
@@ -2471,11 +2476,6 @@ int main(int argc, char **argv)
 	/* Set up the terminal state. */
 	terminal_init();
 
-#ifdef __linux__
-	/* Check whether we're running on a Linux console. */
-	console = (getenv("DISPLAY") == NULL);
-#endif
-
 #ifdef DEBUG
 	fprintf(stderr, "Main: set up windows\n");
 #endif