rustup: rustup component add rust-analyzer-preview does not add rust-analyzer executable to ~/.cargo/bin

Problem

I can install rust-analyzer using rustup component add rust-analyzer-preview but it is not added to ~/.cargo/bin like all other components (clippy, rustfmt, …) and therefore not in the path and not executable.

Steps

Possible Solution(s)

Notes

Output of rustup --version: rustup 1.22.1 (b01adbbc3 2020-07-08) Output of rustup show:

Default host: x86_64-unknown-linux-gnu
rustup home:  /home/user/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
beta-x86_64-unknown-linux-gnu
nightly-2020-03-19-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)
1.37.0-x86_64-unknown-linux-gnu

installed targets for active toolchain
--------------------------------------

wasm32-unknown-unknown
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.46.0-nightly (5db778aff 2020-07-09)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Now that the rust-analyzer is officially announced as default LS, will the binary be installed to default location in next release?

This is the expected behaviour at this point. #2408 added the proxy but I’m considering if it ought to be in TOOLS or DUP_TOOLS because people have installed it via other means before now. For now, as per people who have talked about it, you can run rust-analyzer via rustup run nightly rust-analyzer which you can always set up as a shell alias if you want, or a small shell script if you so desire.

The next release of rustup will contain the proxy either way.

Will we eventually get this working out of the box?

According to the rust-lang blog post from Sept 22, 2022, rust-analyzer is now available via rustup.

The following works for me:

$ rustup component add rust-analyzer
info: downloading component 'rust-analyzer'
info: installing component 'rust-analyzer'
$ rustup run stable rust-analyzer --version
rust-analyzer 1.64.0 (a55dd71 2022-09-19)

According to the blog post, “The next release of rustup will provide a built-in proxy so that running the executable rust-analyzer will launch the appropriate version.”

Note that this change was backed out in 1.23 because rust-analyzer isn’t stable yet: https://github.com/rust-lang/rustup/pull/2408#issuecomment-734899954

I don’t think it’s appropriate for this bug to be closed when the feature it requests is accepted but not yet delivered.

@janos-r I actually didn’t get rustup run stable rust-analyzer working in languages.toml, even though it works in terminal. Had to add it to PATH to make it work, what did you do?

[[language]]
name = "rust"
language-server = { command = "rustup", args = ["run", "stable", "rust-analyzer"] }

Works like a charm. Sry I didnt see your message sooner. In the next release it should be part of the path automatically already tho. This above is just temporarily necessary before that.

I see. Feel free to close.

Maybe we could get rustup run default ... added? I was surprised to find that that doesn’t already work.

@zackw Nice tip! Only "$@" is missing at the end to work with --version or similar arguments.

My complete version of ~/.cargo/bin/rust-analyzer:

#!/bin/bash
set -euo pipefail
exec rustup run "$(rustup show active-toolchain | cut -d' ' -f1)" rust-analyzer "$@"

@lesleyrs This wrapper script may help, put it in $HOME/.local/bin or some other directory on your PATH and chmod +x it:

#! /bin/sh
# as of 2022-11-22 rustup-installed rust-analyzer isn't available
# directly in $PATH
exec rustup run $(rustup show active-toolchain | cut -d' ' -f1) rust-analyzer

I love this, I also got it running on helix with a custom rustup run stable rust-analyzer command, but I am confused about the version. Why does the --version show the version of rustc and not the version of the real rust-analyzer?