title: Magento 2 - Correct way of Module Installation
body: <p>Trying to install sample module in Magento 2 from <a href="https://github.com/darshanb87/magento2-extension-example" rel="nofollow noreferrer">this</a>. Below is the module structure <code>app/code/NameSpace/Module/</code></p>
  
  <p><a href="https://i.stack.imgur.com/MTzlN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MTzlN.png" alt="module image"></a></p>
  
  <p><strong>module.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"&gt;
      &lt;module name="Magentostudy_News" setup_version="0.0.1" schema_version="0.0.1"/&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p><strong>composer.json</strong></p>
  
  <pre><code>{
      "name": "magentostudy/module-news",
      "description": "N/A",
      "require": {
          "php": "~5.5.0|~5.6.0|~7.0.0",
          "magento/module-store": "100.0.0",
          "magento/module-email": "100.0.0",
          "magento/module-ui": "100.0.0",
          "magento/framework": "100.0.0"
      },
      "type": "magento2-module",
      "version": "0.0.1",
      "license": [
          "OSL-3.0",
          "AFL-3.0"
      ],
      "autoload": {
          "files": [ "registration.php" ],
          "psr-4": {
              "Magentostudy\\News\\": ""
          }
      }
      }
  </code></pre>
  
  <p><strong>Registration.php</strong></p>
  
  <pre><code>&lt;?php
  \Magento\Framework\Component\ComponentRegistrar::register(
      \Magento\Framework\Component\ComponentRegistrar::MODULE,
      'Magentostudy_News',
      __DIR__
  );
  </code></pre>
  
  <p>Executing below command to enable module</p>
  
  <pre><code>php ./bin/magento module:enable Magentostudy_News
  </code></pre>
  
  <p>It says <code>there are no commands defined in the "module" namespace.</code> Also on frontend it throws below exception. I am using composer but not github.</p>
  
  <p><code>Fatal error: Uncaught exception 'Magento\Framework\Exception\LocalizedException' with message 'Source class "\Magento\Framework\Module\Updater\Setup" for "Magento\Framework\Module\Updater\SetupFactory" generation does not exist.'</code></p>
  
  <p><strong>CODE EDIT</strong></p>
  
  <p>Added <code>Setup</code> folder with file <code>InstallSchema.php</code> which includes below code</p>
  
  <pre><code>    &lt;?php
  /**
   * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
   */
  
  /* @var $installer \Magento\Setup\Module\SetupModule */
  
  namespace Magentostudy\News\Setup;
  
  use Magento\Framework\Setup\InstallDataInterface;
  use Magento\Framework\Setup\ModuleDataSetupInterface;
  use Magento\Framework\Setup\ModuleContextInterface;
  
  $installer = $this;
  $installer-&gt;startSetup();
  
  /**
   * Creating table magentostudy_news
   */
  $table = $installer-&gt;getConnection()-&gt;newTable(
      $installer-&gt;getTable('magentostudy_news')
  )-&gt;addColumn(
      'news_id',
      \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
      null,
      ['identity' =&gt; true, 'unsigned' =&gt; true, 'nullable' =&gt; false, 'primary' =&gt; true],
      'Entity Id'
  )-&gt;addColumn(
      'title',
      \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
      255,
      ['nullable' =&gt; true],
      'News Title'
  )-&gt;addColumn(
      'author',
      \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
      255,
      ['nullable' =&gt; true,'default' =&gt; null],
      'Author'
  )-&gt;addColumn(
      'content',
      \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
      '2M',
      ['nullable' =&gt; true,'default' =&gt; null],
      'Content'
  )-&gt;addColumn(
      'image',
      \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
      null,
      ['nullable' =&gt; true,'default' =&gt; null],
      'News image media path'
  )-&gt;addColumn(
      'created_at',
      \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
      null,
      ['nullable' =&gt; false],
      'Created At'
  )-&gt;addColumn(
      'published_at',
      \Magento\Framework\DB\Ddl\Table::TYPE_DATE,
      null,
      ['nullable' =&gt; true,'default' =&gt; null],
      'World publish date'
  )-&gt;addIndex(
      $installer-&gt;getIdxName(
          'magentostudy_news',
          ['published_at'],
          \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX
      ),
      ['published_at'],
      ['type' =&gt; \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
  )-&gt;setComment(
      'News item'
  );
  $installer-&gt;getConnection()-&gt;createTable($table);
  $installer-&gt;endSetup();
  </code></pre>
  
  <ol>
  <li>What is the correct way to install <strong>Magento 2</strong> modules ?</li>
  <li>Any crucial step I missed ?</li>
  </ol>
  
  <p>Reference URL : <a href="http://mageinferno.com/blog/setting-up-magento-2-module-right-way-composer-packagist" rel="nofollow noreferrer">http://mageinferno.com/blog/setting-up-magento-2-module-right-way-composer-packagist</a></p>