Looking at that, the temp table is a heap, so unless tempdb is on slow disk OR tempdb is nearly full and your INSERT is causing a lot of auto-grow, it isn't likely the temp table (technically table variable) that is causing your problem - it is your SELECT.
Try commenting out the "INSERT INTO" part of your query and see how long that select takes to complete. You likely need to tune your @installs table OR change your nested select. Pretty sure that nested select is going to be what hurts your performance the most.
I would recommend the following to help with query tuning:
1 - post the DDL for all relevant objects
2 - post sample INSERT statements to get some data into the table
3 - post the expected output
4 - for performance tuning, posting the execution plan (not an image of it, but the XML so we can consume it and review it) is your best bet. OR you can review it yourself and may see what needs tuning.
With that particular query, you may get a performance boost by adding some indexes onto the @installs table (will need to convert it to a temp table rather than a table variable if I remember right).
DECLARE @table TABLE <-- table variable
CREATE TABLE #table <-- temp table
Table variables exist within the transaction, temp tables exist within the session.
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.