Running `rustdoc` isn't working

I started going through the Rust Doc book, following along step by step, using Cargo new to create a new docs project directory. Then the tutorial says to run this line:

rustdoc src/lib.rs

and I get the following error:

jtreagan@WillowCreek:~/programming/rust/others/docs$ $ rustdoc src/lib.rs
$: command not found

I thought that was rather strange as I was under the impression that rustdoc installed when I first ran rustup a long, long time ago. Anyway I ran rustup update just to make sure and sure enough rustdocs installed.

// snip
info: removing previous version of component 'rust-docs'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: removing previous version of component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
// snip

Yet I still get that command not found error.

What am I doing wrong?

Now that's embarassing. Never mind. I copied the $ at the beginning of the line. It's working now. Sorry about that.

2 Likes

rustdoc is not a separate rustup component, it is installed with rustc, so it should be always available, as long as rustc is available.

it may be that your PATH environment varialbe may not be setup correctly, but you can run rustup and cargo without problem so I'm a little confused. but worth a check anyway, what's the output if you run echo $PATH?

also, can you run rustdoc through the rustup run command? e.g. what's the output
if you run rustup run stable rustdoc? replace stable with your installed toolchain if stable is not installed.

1 Like