During my attempt to automate some task with rake on ubuntu, I've encountered scenarios that required packed might not already exist on target machine. What is a good way to check if certain package was already installed on the system and respond accordingly?
For example, I'd like to run 'npm start' within certain task, but I'd want to know if npm has already been installed on the system, thus giving user the correct error message. I'm also fine doing it with thor if it's possible at all.
You can run system command from Ruby scripts using the Kernel.system
method. Consider something like the following:
fail unless system('which npm')