Answers: <p>If the end result would be entirely contained in a directory somewhere you could simply archive that directory after the installation on one machine and restore it on the new machine. It does work for <em>some</em> apps.</p>
  
  <p>But after going through the <a href="https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/" rel="nofollow noreferrer">Ubuntu 18.04: How to install OpenCV</a> procedure and peeking into the makefiles I believe this wouldn't be applicable to OpenCV: its artefacts are spread in various places on a Ubuntu system.</p>
  
  <p>But I <em>think</em> it's possible to significantly reduce the installation time by skipping the actual build process, which appears to be the bulk of the process. From the above referenced procedure (which I'll also use in describing the proposed solution):</p>
  
  <blockquote>
    <p>This process may take 30 minutes or longer, so go for a nice walk if
    you are able.</p>
  </blockquote>
  
  <p>I'll re-use the referenced procedure for describing the proposal, with a few tweaks (I'd like to think that the tweaks would easily be portable to future/similar versions of the procedure):</p>
  
  <p><strong>In the initial installation:</strong></p>
  
  <ul>
  <li><p>after the build completes but before the <strong>Installing and verifying OpenCV</strong> step insert:</p>
  
  <p><strong>Step 4a: save the pre-built official OpenCV source tree to S3</strong></p>
  
  <p>Follow <a href="https://serverfault.com/q/254599">Copying from s3 to EC2 instance</a> instructions for S3 access setup, then run:</p>
  
  <pre><code>tar cvfz pre_built_opencv.tgz opencv*
  s3cmd put pre_built_opencv.tgz s3://&lt;bucket_name&gt;
  </code></pre>
  
  <p>Optional: you can remove the local archive copy now:</p>
  
  <pre><code>rm pre_built_opencv.tgz
  </code></pre></li>
  </ul>
  
  <p><strong>In the subsequent installations:</strong></p>
  
  <ul>
  <li><p>replace <strong>Step #2: Download the official OpenCV source</strong> with:</p>
  
  <p><strong>Step #2: Extract the pre-built official OpenCV source tree from S3</strong></p>
  
  <p>Follow <a href="https://serverfault.com/q/254599">Copying from s3 to EC2 instance</a> instructions for S3 access setup, then run:</p>
  
  <pre><code>cd ~
  s3cmd get s3://&lt;bucket_name&gt;/pre_built_opencv.tgz pre_built_opencv.tgz
  tar xvzf pre_built_opencv.tgz
  </code></pre>
  
  <p>Optional: you can remove the local archive copy now:</p>
  
  <pre><code>rm pre_built_opencv.tgz
  </code></pre></li>
  <li><p>in <strong>Step #4: Configure and compile OpenCV for Ubuntu 18.04</strong>:</p>
  
  <ul>
  <li>skip the <strong>Configure OpenCV with CMake</strong> section</li>
  <li><p>replace the <strong>Compiling OpenCV on Ubuntu 18.04</strong> section with:</p>
  
  <p><strong>Enter the pre-built OpenCV build directory</strong></p>
  
  <pre><code>cd ~/opencv/build
  </code></pre></li>
  </ul></li>
  </ul>
  
  <p>I didn't run it myself, but I think it <em>should</em> work, at least for VMs of the same type. </p>
  
  <p>I'd 1st try the same even for different VM types. If that doesn't work then I'd re-run the initial installation for them, using a different archive filename.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-03-16T20:58:51.790Z
Answers: 2019-03-16T20:58:51.790Z
Answers: Dan Cornilescu
Body: <p>Every time I spawn a new host I need to compile OpenCV on Ubuntu following official manual. The problem is that it takes about 20-30 minutes depends on the VM type. Is it somehow possible to store the compiled OpenCV i.e. at S3 as a package or any othey way to avoid compilation?</p>
  
  <p>create a VM image doesn't fit my purpose</p>
  
Tags: <amazon-ec2><amazon-s3>
Title: compiled opencv copy to another host
UserDisplayName: user3909893
ThreadText: # compiled opencv copy to another host
  
  (Asked by: username_0 on 2019-03-16)
  
  Every time I spawn a new host I need to compile OpenCV on Ubuntu following official manual. The problem is that it takes about 20-30 minutes depends on the VM type. Is it somehow possible to store the compiled OpenCV i.e. at S3 as a package or any othey way to avoid compilation?
  
  create a VM image doesn't fit my purpose
  
  **Tags:** amazon-ec2, amazon-s3
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-16. Score: 1 | Accepted answer
  
  If the end result would be entirely contained in a directory somewhere you could simply archive that directory after the installation on one machine and restore it on the new machine. It does work for *some* apps.
  
  But after going through the [Ubuntu 18.04: How to install OpenCV](https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/) procedure and peeking into the makefiles I believe this wouldn't be applicable to OpenCV: its artefacts are spread in various places on a Ubuntu system.
  
  But I *think* it's possible to significantly reduce the installation time by skipping the actual build process, which appears to be the bulk of the process. From the above referenced procedure (which I'll also use in describing the proposed solution):
  
  > This process may take 30 minutes or longer, so go for a nice walk if
  > you are able.
  
  I'll re-use the referenced procedure for describing the proposal, with a few tweaks (I'd like to think that the tweaks would easily be portable to future/similar versions of the procedure):
  
  **In the initial installation:**
  
  * after the build completes but before the **Installing and verifying OpenCV** step insert:
  
    **Step 4a: save the pre-built official OpenCV source tree to S3**
  
    Follow [Copying from s3 to EC2 instance](https://serverfault.com/q/254599) instructions for S3 access setup, then run:
  
    ```
    tar cvfz pre_built_opencv.tgz opencv*
    s3cmd put pre_built_opencv.tgz s3://<bucket_name>
  
    ```
  
    Optional: you can remove the local archive copy now:
  
    ```
    rm pre_built_opencv.tgz
  
    ```
  
  **In the subsequent installations:**
  
  * replace **Step #2: Download the official OpenCV source** with:
  
    **Step #2: Extract the pre-built official OpenCV source tree from S3**
  
    Follow [Copying from s3 to EC2 instance](https://serverfault.com/q/254599) instructions for S3 access setup, then run:
  
    ```
    cd ~
    s3cmd get s3://<bucket_name>/pre_built_opencv.tgz pre_built_opencv.tgz
    tar xvzf pre_built_opencv.tgz
  
    ```
  
    Optional: you can remove the local archive copy now:
  
    ```
    rm pre_built_opencv.tgz
  
    ```
  * in **Step #4: Configure and compile OpenCV for Ubuntu 18.04**:
  
    + skip the **Configure OpenCV with CMake** section
    + replace the **Compiling OpenCV on Ubuntu 18.04** section with:
  
      **Enter the pre-built OpenCV build directory**
  
      ```
      cd ~/opencv/build
  
      ```
  
  I didn't run it myself, but I think it *should* work, at least for VMs of the same type.
  
  I'd 1st try the same even for different VM types. If that doesn't work then I'd re-run the initial installation for them, using a different archive filename.
  
  
  ---
  
  