Menu

How to get the version in Magento 2

If you want to know magento version, please use code as follow:

- Way 1:

	
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface');
echo $productMetadata->getVersion();
	

- Way 2:

	
class your_class_name{

	protected productMetadata;
	
	public function __construct(
        \Magento\Framework\App\ProductMetadataInterface $productMetadata
    ) {
        $this->productMetadata = $productMetadata;
    }
	
	public function getMagentoVersion(){
        return $this->productMetadata->getVersion();
    }
}