Repository: readthedocs/readthedocs.org

Issue:
Build failing with `/bin/bash: line 1: asdf: command not found`
## Details

* Read the Docs project URL: https://readthedocs.org/projects/exordium/
* Build URL (if applicable): https://readthedocs.org/projects/exordium/builds/19855052/
* Read the Docs username (if applicable): https://readthedocs.org/profiles/apocalyptech/

## Expected Result

Build should succeed

## Actual Result

Build is failing with `/bin/bash: line 1: asdf: command not found` -- I've also tried re-building old versions which used to work fine, and they're failing with the same error.  I don't specify `asdf` anywhere in my repo or RTD configs, so I'm not sure where that's coming from.  Let me know if I can provide any more info!



Discussion:
Ditto, was just opening the same issue! I'll drop the info here since I already typed all of it :smile: 

## Details

* Read the Docs project URL: Multiple including https://readthedocs.org/projects/dash-user-docs/
* Build URL (if applicable):
  * Failed: https://readthedocs.org/projects/dash-user-docs/builds/19855245/
  * Successful: https://readthedocs.org/projects/dash-user-docs/builds/19852825/
* Read the Docs username (if applicable): https://readthedocs.org/profiles/thephez/

## Expected Result

Project builds successfully as usual

## Actual Result

Builds failing today with this error:

```
/bin/bash: line 1: asdf: command not found
```

### Screenshots
Failed build:
![image](https://user-images.githubusercontent.com/8145677/226678537-67941146-79f1-4bb6-97e1-0401fb42b266.png)

Successful build of same commit earlier today:
![image](https://user-images.githubusercontent.com/8145677/226679272-8d264667-8777-4351-8c92-2197a22d47c5.png)

Same :disappointed:
  Failed: https://readthedocs.org/projects/crowsetta/builds/19854975/
  Last successful: https://readthedocs.org/projects/crowsetta/builds/19844422/
(Hi @NickleDave !)
Similar but slightly different issue:
![Screen Shot 2023-03-21 at 10 47 01](https://user-images.githubusercontent.com/55767766/226681867-6ecd8e0c-db5d-48a1-948b-e249aa0abd9a.png)

Failed:https://readthedocs.org/projects/pyomo/builds/19855262/
Last successful: https://readthedocs.org/projects/pyomo/builds/19854787/


Resolving patch:
diff --git a/readthedocs/doc_builder/environments.py b/readthedocs/doc_builder/environments.py
--- a/readthedocs/doc_builder/environments.py
+++ b/readthedocs/doc_builder/environments.py
@@ -312,15 +312,33 @@ def run(self):
         # /home/docs/.asdf/shims:/home/docs/.asdf/bin
         #  :/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
         # docs@bfe702e31cdd:~$
-        asdf_paths = (
-            f"/home/{settings.RTD_DOCKER_USER}/.asdf/shims"
-            f":/home/{settings.RTD_DOCKER_USER}/.asdf/bin"
-        )
-        if settings.RTD_DOCKER_COMPOSE:
-            asdf_paths += ":/root/.asdf/shims:/root/.asdf/bin"
-
+        #
+        # On old Docker images we have different PATH:
+        #
+        # $ sudo docker run -it readthedocs/build:latest /bin/bash
+        # docs@656e38a30fa4:/$ echo $PATH
+        # /home/docs/.pyenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/docs/.conda/bin:/home/docs/.pyenv/bin
+        # docs@656e38a30fa4:/$
         default_paths = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-        environment["PATH"] = f"{asdf_paths}:{default_paths}"
+        if self.build_env.container_image in (
+            "readthedocs/build:ubuntu-22.04",
+            "readthedocs/build:ubuntu-20.04",
+        ):
+            # Use ASDF path for newer images
+            python_paths = "/home/docs/.asdf/shims:/home/docs/.asdf/bin"
+            paths = f"{python_paths}:{default_paths}"
+
+            # On local development, we are using root user
+            if settings.RTD_DOCKER_COMPOSE:
+                paths = paths.replace("/home/docs/", "/root/")
+        else:
+            # Use PYENV for older images
+            paths = (
+                "/home/docs/.pyenv/shims:/home/docs/.cargo/bin"
+                f":{default_paths}:"
+                "/home/docs/.conda/bin:/home/docs/.pyenv/bin"
+            )
+        environment["PATH"] = paths
 
         # Prepend the BIN_PATH if it's defined
         if self.bin_path:


Test patch: