11

I'm trying to figure out how to use rustc & cargo from my WSL. I use VS Code and Rust (rls) plugin and can compile my code but there is a problem with RLS:

Couldn't start client Rust Language Server

Rustup not available. Install from https://www.rustup.rs/

How i can solve this problem?

Community
  • 1
  • 1
aitvann
  • 1,289
  • 2
  • 8
  • 10
  • I had the same problem with `Remote SSH` and Linux VM wunning on Windows (Virtual Box). What helped was manually installing Rust Language Server `rustup component add rls rust-analysis rust-src` and rebooting the VM. Not sure about the root cause though. – Majus Misiak Oct 13 '19 at 18:31

6 Answers6

18

Set rust-client.rustupPath in VSCode settings:

{
    "rust-client.rustupPath": "~/.cargo/bin/rustup"
}

If you're using WSL on Windows then make sure you edit Rust extension WSL settings, not user/local settings.

Tutorial:

Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89
  • 1
    Hi Daniel, in my vscode (launched from wsl2), I only see User and Workspace tabs, not the Remote [WSL: Ubuntu-20.04] tab. Any idea why? – Paulus Feb 23 '21 at 16:20
  • @Paulus Have you figured it out? I have no idea. – Daniel Kmak Mar 15 '21 at 17:35
  • When using the Rust (RLS) extension: File / Preferences / Settings and filter on 'rustup' will allow you to change the Rustup Path. NOTE: rust-analyzer does not need this, and seems to be the preferred extension. – Taylored Web Sites Feb 16 '23 at 15:03
0

I had this problem as well with WSL and Visual Studio Code. The problem seems to stem from the fact that the Rust Language Server needs to find rustup in your path. We both probably followed the same path of using a package manager to install cargo, and therefore, the rust compiler tools. This does not include rustup which you can actually use to keep the rust toolchain up-to-date. rustup also appears to be the preferred method of installing the rust toolchain on your system.

After installing rustup with the default setup, you should see a .rustup directory in your home directory. This is where the toolchain lives. The install text all stated that it would add the toolchain to your environment path after logging out and back in, but I didn't have luck with this. I'm currently using fish instead of bash and had to update the configuration to include the toolchain at startup. Once I did that, I was able to have VSCode properly install and run the RLS.

Scott
  • 370
  • 2
  • 7
0

This worked for me for in a remote SSH environment with Ubuntu 20.04

  1. Edit .profile and .bashrc files in the user home directory

In .profile, comment the following line:

export PATH="$HOME/.cargo/bin:$PATH"

In both, add the following line:

[[ ":$PATH:" != *":$HOME/.cargo/bin:"* ]] && PATH="$HOME/.cargo/bin:${PATH}"
  1. Reboot.
Giuseppe Galano
  • 10,412
  • 1
  • 12
  • 10
  • 1
    You shouldn't need to reboot, as you can simply [`source`](https://ss64.com/bash/source.html) the `.profile`/ `.bashrc` files – MindSwipe Aug 03 '20 at 09:31
0

Even though if I run:

which rustup
/Users/justincalleja/.cargo/bin/rustup

A simple entry of rustup in the VSCode settings for:

"Rust-client: Rustup Path Path to rustup executable. Ignored if rustup is disabled."

wasn't enough and I had to put the absolute path to the rustup binary as shown above. After doing so, I reloaded the window and was then asked to download missing components (or dependencies - the prompt is gone now I forgot). After doing this, the VSCode plugin seems to be working fine. I can format the code at least.

So it looks like it's some mismatch with VSCode's PATH and the PATH on my system. I'm not sure what it is but if you just want to get the extension to work, try using the absolute path to rustup in your Settings.

(Note: source "$HOME/.cargo/env" is added automatically to your startup files like .bashrc. First thing I tried was adding it to the startup file of zsh; the shell I'm using and to which it wasn't added. But that doesn't work either. I'm using rustc 1.49.0 (e1884a8e3 2020-12-29) ).

justin
  • 3,357
  • 1
  • 23
  • 28
0

So... I'm running Rust on Windows 10 and I experienced this same issue. My Rust version is 1.24.3, my VSCode version is 1.63.2.

  1. The first thing you need to do is add "%USERPROFILE%.cargo\bin" to your environment variables

  2. The next solution that worked for me can be found in this tutorial: Rust on Windows and Visual Studio Code

Divinity
  • 93
  • 2
  • 7
0

i am running VSCode on mac, and using remote development.the remote server is ubuntu 20. i had this problem, added rust-client.rustupPath to vscode settings and killed the vscode-server on remote server to fix this problem. now it work.

min.wang
  • 1
  • 1