// Tutorial //

Como instalar o Composer no Ubuntu 20.04 [Início rápido]

Published on June 11, 2020
Default avatar

By Erika Heidi

Developer Advocate

Português
Como instalar o Composer no Ubuntu 20.04 [Início rápido]

Introdução

Neste guia de início rápido, instalaremos o Composer em um servidor Ubuntu 20.04.

Para uma versão mais detalhada deste tutorial, contendo explicações mais detalhadas para cada passo, confira Como instalar e configurar o Composer no Ubuntu 20.04.

Pré-requisitos

Para seguir este guia, você precisará ter acesso a um servidor Ubuntu 20.04 como um usuário sudo.

Passo 1 — Instalar dependências

Comece atualizando o cache do gerenciador de pacotes e instalando as dependências necessárias, incluindo o php-cli:

  1. sudo apt update
  2. sudo apt install php-cli unzip

Passo 2 — Baixar e instalar o Composer

Certifique-se de estar em seu diretório home. Em seguida, baixe o instalador do Composer usando o curl:

  1. cd ~
  2. curl -sS https://getcomposer.org/installer -o composer-setup.php

Em seguida, vamos verificar se o instalador baixado corresponde ao hash SHA-384 para o instalador mais recente encontrado na página Composer Public Keys / Signatures.

Usando o curl, pegue a última assinatura e armazene-a em uma variável shell:

  1. HASH=`curl -sS https://composer.github.io/installer.sig`

Agora, execute o seguinte código PHP para verificar se o script de instalação está seguro para ser executado:

  1. php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Você verá o seguinte resultado:

Output
Installer verified

Nota: se o resultado disser Installer corrupt (Instalador corrompido), você precisará repetir o processo de download e verificação até que você tenha um instalador verificado.

O seguinte comando baixará e instalará o Composer como um comando de sistema chamado composer como um comando chamado composer, em usr/local/bin:

  1. sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Você verá um resultado parecido com este:

Output
All settings correct for using Composer Downloading... Composer (version 1.10.5) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer

Para testar a sua instalação, execute:

  1. composer
Output
______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.10.5 2020-04-10 11:44:22 Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information --no-plugins Whether to disable plugins. -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory. --no-cache Prevent use of the cache -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug ...

Isso verifica que o Composer foi instalado com sucesso em seu sistema e está disponível em todo o sistema.

Tutoriais relacionados

Aqui estão os links para os guias mais detalhados relacionados a este tutorial:

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up now
About the authors
Default avatar

Developer Advocate

Dev/Ops passionate about open source, PHP, and Linux.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!