My plugin does not install correctly if a previous version is still installed

Quick and easy.

if ( is_plugin_active( 'plugin-folder-name/main-plugin-file.php' ) )
    deactivate_plugins( '/plugin-folder-name/main-plugin-file.php' );

It’s important to note the is_plugin_active string is slightly different than the deactivate_plugins string.