Install Composer on Ubuntu 14.04

Step 1 — Installing the Dependencie

First, update the package manager cache by running:

$sudo apt-get update

Now, let’s install the dependencies. We’ll need curl in order to download Composer and php5-cli for installing and running it. git is used by Composer for downloading project dependencies. Everything can be installed with the following command:

$sudo apt-get install curl php5-cli git

Step 2 — Downloading and Installing Composer

Composer installation is really simple and can be done with a single command:

$curl -sS https://getcomposer.org/installer | sudo php – –install-dir=/usr/local/bin –filename=composer

To test your installation, run:

$composer

Step 3 — Generating the composer.json File

Requiring a Package

$composer require cocur/slugify

Output
Using version ^1.3 for cocur/slugify
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing cocur/slugify (v1.3)
    Downloading: 100%         
Writing lock file
Generating autoload files

As you can see from the output, Composer automatically decided which version of the package should be used. If you check your project’s directory now, it will contain two new files: composer.json and composer.lock, and a vendor directory:

When installing a project that already contains a composer.json file, you need to run composer install in order to download the project’s dependencies.

Step 4 — Including the Autoload Script

Composer also provides an autoload script that you can include in your project to get autoloading for free. This makes it much easier to work with your dependencies and define your own namespaces.

The only thing you need to do is include the vendor/autoload.php file in your PHP scripts, before any class instantiation.

<?php
require __DIR__ . '/vendor/autoload.php';

use Cocur\Slugify\Slugify;

$slugify = new Slugify();

echo $slugify->slugify('Hello World, this is a long sentence and I need to make a slug from it!');

Step 5 — Updating the Project Dependencies

composerupdate composer update vendor/package vendor2/package2


参考:
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-14-04

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值