You can make an alias xo (name it whatever you like) that reruns the last command without printing any of its output, then runs the last line of that output as a command.
alias xo='$($(fc -ln -1) |& tail -1)'
Then after you attempt to run myapp and are told the command you can use to install mypackage which provides myapp, you can simply type xo and press Enter and the command to install mypackage will run.
How This Works
$(fc -ln -1) behaves much like the history expansion !!. !! doesn't work in an alias or function definition, but fc (and command substitution with $( )) does.
$(fc -ln -1) |& tail -1 reruns the last command, piping its standard output and standard error to tail -1, which discards everything but the last line.
Enclosing that in an outer command substitution causes the last line to be run as a command. Word splitting is performed on it (since the whole thing is not enclosed in " quotes), which is what you want.
Sources Cited