diff --git a/.bazelrc b/.bazelrc
index 6c70b2e95..308ada04d 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -5,6 +5,7 @@ build --enable_platform_specific_config
 # On all platforms, provide: PYTHON3_BIN_PATH=python
 ###############################################################################
 build --action_env=PATH
+build --action_env=LD_LIBRARY_PATH
 # For --compilation_mode=dbg, consider enabling checks in the standard library as well (below).
 build --compilation_mode=opt
 # Using C++ 17 on all platforms.
diff --git a/BUILD.bazel b/BUILD.bazel
index 4ff33538e..6fa0a2bd9 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -292,6 +292,12 @@ PLASMA_LINKOPTS = [] + select({
     ],
 })
 
+CXX_LINKOPTS = select({
+    "//conditions:default": [
+        "-lstdc++fs",
+    ],
+})
+
 cc_library(
     name = "plasma_client",
     srcs = [
@@ -475,6 +481,7 @@ cc_binary(
     name = "raylet",
     srcs = ["src/ray/raylet/main.cc"],
     copts = COPTS,
+    linkopts = CXX_LINKOPTS,
     visibility = ["//java:__subpackages__"],
     deps = [
         ":ray_util",
@@ -560,6 +567,7 @@ cc_binary(
         "src/ray/gcs/gcs_server/gcs_server_main.cc",
     ],
     copts = COPTS,
+    linkopts = CXX_LINKOPTS,
     visibility = ["//java:__subpackages__"],
     deps = [
         ":gcs_server_lib",
diff --git a/cpp/BUILD.bazel b/cpp/BUILD.bazel
index 3b12acf6c..c4b735457 100644
--- a/cpp/BUILD.bazel
+++ b/cpp/BUILD.bazel
@@ -3,6 +3,12 @@
 
 load("//bazel:ray.bzl", "COPTS")
 
+CXX_LINKOPTS = select({
+    "//conditions:default": [
+        "-lstdc++fs",
+    ],
+})
+
 cc_binary(
     name = "libray_api.so",
     copts = COPTS,
@@ -63,6 +69,7 @@ cc_binary(
         "src/ray/worker/default_worker.cc",
     ]),
     copts = COPTS,
+    linkopts = CXX_LINKOPTS,
     linkstatic = True,
     deps = [
         "ray_api",
diff --git a/python/setup.py b/python/setup.py
index c361a6880..16bfd6549 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -482,7 +482,7 @@ def build(build_python, build_java, build_cpp):
             ] + pip_packages,
             env=dict(os.environ, CC="gcc"))
 
-    version_info = bazel_invoke(subprocess.check_output, ["--version"])
+    version_info = bazel_invoke(subprocess.check_output, ["version", "--gnu_format"])
     bazel_version_str = version_info.rstrip().decode("utf-8").split(" ", 1)[1]
     bazel_version_split = bazel_version_str.split(".")
     bazel_version_digits = [