For me, the best way is just to start writing it. I've written a book about a Java library last year named "Practical Vavr" [1], I had the idea since some weeks/months and with the COVID situation having time at home, just told to myself now is the time.
Didn't thought a lot about anything, except for how the book should be laid out, I thought the process was interesting so I went full on it, discovered leanpub and other websites that makes the process easy as just writing some Markdown.
I think that the hardest thing is the marketing around the book, how to tell the world you wrote it and why they should be interested in reading it (and buying it). I just posted it here and there on the web (reddit, twitter mainly), didn't made a lot of fuss about it, I don't know how anyway.
In the end it was more about the experience of writing one and finishing it, than making big money (even if I was able to reach almost 100 people totally unknown people who were kind enough to trust that the content would be good and buy it).